在bootstrap模式下不会触发html文本框和html按钮的客户端事件

时间:2014-03-03 04:57:42

标签: javascript jquery twitter-bootstrap

我调用了textbox onchange事件和按钮单击事件。 bootstrap模态体中的文本框和html按钮。这些事件不会被触发。

<script type="text/javascript">
    $(document).ready(function () {
                 $('#mybutton').on('click', function (evt) {
                alert("htmlbutton clik");
            });
            $("#input1").change(function () {
                alert("htmltext changed");
            });
         });
</script>
<div class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
          <input type="button" id="mybutton" value="htmlbutton" />
          <input type="text" id="input1" value="htmltext" />
  </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>

1 个答案:

答案 0 :(得分:0)

您的代码看起来很好。不确定你是否包含Jquery这里是完整的代码

<html>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" ></script>
<script type="text/javascript">
    $(document).ready(function () {
                 $('#mybutton').on('click', function (evt) {
                alert("htmlbutton clik");
            });

         });
</script>
<div class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
          <input type="button" id="mybutton" value="htmlbutton" />
          <input type="text" id="input1" value="htmltext" />
  </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>
<script>
 $("#input1").on('change',function () {
                alert("htmltext changed");
            });
$("#input1").on('keypress',function () {
alert("htmltext changed");
});

</script>
</html>

为了更好地理解代码,密钥按键是否分开。