a.html
<div><button class="button" >点我达</button> </div>
b.html
<html> <head><script type="text/javascript" src="./js/jquery-1.0.1.js"></script><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head><body><div class="div"></div> </body><script type="text/javascript">var a = jQuery(".div");$(".div").load("http://localhost:8080/a.html", null, function (response,status,xhr) {if(status == "success") {alert("导入成功");$(".button").click(function () {alert("绑定点击事件触发")})}});</script> </html>
乱码和文件的编码也有关系
b.html通过jQuery导入a.html中的片段,然后给a.html中的button绑定点击事件。