.append无法加载已有js文件,解决实例
js:
1 /** 2 * 3 */ 4 $(function(){ 5 $(document).on("click","a",function(){ 6 alert("点击成功"); 7 }); 8 9 $("#add").click(function(){ 10 $("#mydiv").append("<a>点击</a>"); 11 }); 12 });
html:
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <script type="text/javascript" src="assets/jquery-3.3.1.min.js"></script> 7 <script type="text/javascript" src="test.js"></script> 8 <script type="text/javascript"> 9 </script> 10 </head> 11 <body> 12 13 <a>点击</a><button id="add">add</button> 14 <div id="mydiv"></div> 15 </body> 16 </html>