您应该
.on用来将处理程序绑定到绑定执行期间已经存在的另一个元素,例如
<body>或,
document并让它检测子事件。但理想情况下,应将其绑定到已加载内容的最近的公共父级。
演示
//bind to the body a "click" handler for elements that have class names of "hello"$('body').on('click','.hello',function(){ alert("Hello Clicked");})
您应该
.on用来将处理程序绑定到绑定执行期间已经存在的另一个元素,例如
<body>或,
document并让它检测子事件。但理想情况下,应将其绑定到已加载内容的最近的公共父级。
演示
//bind to the body a "click" handler for elements that have class names of "hello"$('body').on('click','.hello',function(){ alert("Hello Clicked");})