donglong2856 2014-07-17 14:03
浏览 32
已采纳

jQuery加载和更改[重复]

This question already has an answer here:

I have a 'test.html' and a 'test.php' files.

The 'test.html':

<html>
  <head>
    <script type="text/javascript" src="/js/jquery-1.8.2.js"></script>
  </head>
  <body>
    <p>Hello</p>
  </body>
</html>

<script type="text/javascript">
  $(function() {
    $("p").on('click', function() {
      $(this).load("test.php");
      $(this).off();
    });
  });
</script>

<script type="text/javascript">
  $(function() {
    $("#sel_1").on('change', function() {
      alert("SELECT changed!");
    });
  });
</script>

And the 'test.php':

<?php
  echo "<select id='sel_1'>";
  echo "<option>one</option>";
  echo "<option>two</option>";
  echo "<option>three</option>";
  echo "</select>";
?>

When i click the 'p' item (Hello), then the jQuery load a new content into 'p'.

But when i change a select item, I would like to see the alert messages, but it will not appear. How can I solve this?

</div>
  • 写回答

2条回答 默认 最新

  • duanna3634 2014-07-17 14:32
    关注

    This should work:

    <script type="text/javascript">
      $(function() {
        $('body').on('change', "#sel_1", function() {
          alert("SELECT changed!");
        });
      });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效