为了账号安全,请及时绑定邮箱和手机立即绑定

jquery ajax加载页面中的js代码如何执行?

jquery ajax加载页面中的js代码如何执行?

守候你守候我 2018-08-13 13:10:19
index.js$(function(){     $("#btn").on("click",function(){         $.ajax({            url: 'page.html',            type: 'post',            success: function (responseText) {                 $('#div1').html(responseText);             }         });     });     $("#test").on("click",function(){         alert('hello world!');     }); });demo.html<script type="text/javascript" src="index.js"></script><input type="button" id="btn" value="加载" /><div id="div1"></div>page.html<input type="button" id="test" value="执行" />请问:当demo页面加载page页面后,html代码就会被加载到div1容器里面,之间加载的index.js对于新内容不起作用,点击执行按钮是无效的。请问如何让加载的页面中javascript代码能够执行?实践场景:页面依赖第三方表单验证(通过class属性定义验证规则),动态新添加了表单元素,可是新表单元素的验证规则不起作用。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 742 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信