te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Showing Text-box after Button click event - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Showing Text-box after Button click event - Stack Overflow

programmeradmin2浏览0评论

I'm trying to generate a text-box after a button click event. The code is as follows.

<div id="weleDiv"  class="answer_list" > WELCOME </div>
<input type="button" name="answer" value="Show Div" onclick="showDiv()" />
</div>
<?php if(isset($_POST['button'])) { ?>
<?php echo "<script type=\"text/javascript\">
   function showDiv() {

   <input type="text" id="textInput" value="..." />
   document.getElementById('weleDiv').style.display = "block"; </script> ";
   }
   </script>" ?> ;
<?php } ?>

But the button click event function is not working properly. Any thoughts?

I'm trying to generate a text-box after a button click event. The code is as follows.

<div id="weleDiv"  class="answer_list" > WELCOME </div>
<input type="button" name="answer" value="Show Div" onclick="showDiv()" />
</div>
<?php if(isset($_POST['button'])) { ?>
<?php echo "<script type=\"text/javascript\">
   function showDiv() {

   <input type="text" id="textInput" value="..." />
   document.getElementById('weleDiv').style.display = "block"; </script> ";
   }
   </script>" ?> ;
<?php } ?>

But the button click event function is not working properly. Any thoughts?

Share Improve this question edited Sep 21, 2017 at 6:55 Ali Hesari 1,9495 gold badges27 silver badges54 bronze badges asked Sep 21, 2017 at 4:43 Ryan OscarRyan Oscar 2791 gold badge4 silver badges20 bronze badges 2
  • Please post properly formatted HTML – Parag Jadhav Commented Sep 21, 2017 at 4:46
  • I think the syntax inside the script tag is invalid. – Avery246813579 Commented Sep 21, 2017 at 4:46
Add a ment  | 

4 Answers 4

Reset to default 7

You can also create css and make visible textfield on button click

Hope below example will help you

function onButtonClick(){
  document.getElementById('textInput').className="show";
}
.hide{
  display:none;
}
.show{
  display:block;
}
<div class="answer_list" > WELCOME </div>
<input type="button" name="answer" value="Show Text Field" onclick="onButtonClick()" />
<input class="hide" type="text" id="textInput" value="..." />

You don't need use PHP! Is better to use Jquery for this action.

$(document).ready(function() {
  $("#myButton").click(function() {
    $("#myButton").after('<input type="text" id="textInput" value="">');
  });
});
input{
  display:block;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="weleDiv" class="answer_list"> WELCOME </div>
<br>
<input type="button" id="myButton" name="answer" value="Show Div" />

Hi Ryan please check this code it will create a text box and add it before button.

 <div id="weleDiv"  class="answer_list" > WELCOME </div>
 <div id="tbox_div">
 </div>
 <input type="button" name="answer" value="Show Div" onclick="showDiv()" />
 <script>
 function showDiv(){
var newtextbox ='';
if (!document.getElementById("textInput")) {
 newtextbox += '<input type="text" id="textInput" value="..." />'; 
    document.getElementById('tbox_div').innerHTML+=newtextbox;
  }
  }

if you want to add more that one text boxes then remove this if condition.

if (!document.getElementById("textInput"))

Using JQuery you can do it like, here's a FIDDLE

<div id="weleDiv" class="answer_list"> WELCOME </div>
<br>
<input type="button" id="myButton" name="answer" value="Show Div" />
<br>
<br>
<input type="text" id="textInput" value="" hidden/>

$(document).ready(function() {
  $("#myButton").click(function() {
    $("#textInput").show();
  });
});

Using Plain JavaScript, here's a FIDDLE

<div id="weleDiv" class="answer_list"> WELCOME </div>
<br>
<input type="button" id="myButton" name="answer" value="Show Div" onclick="showInputBox()" />
<br>
<br>
<input type="text" id="textInput" value="" hidden/>

<script>
  function showInputBox() {
    if (document.getElementById("textInput")) {
      document.getElementById("textInput").style.display = 'block';
      alert("Yes");
    } else {
      //IF INPUT BOX DOES NOT EXIST
      var inputBox = document.createElement("INPUT");
      inputBox.setAttribute("type", "text");
      inputBox.setAttribute("id", "dynamicTextInput");
      document.body.appendChild(inputBox);
      alert("No");
    }
  }
</script>
发布评论

评论列表(0)

  1. 暂无评论