jQueryon()方法—向未创建的元素添加事件处理程序
作者:手机用户2502931221 | 来源:互联网 | 2023-02-03 15:04
向未来的元素添加事件处理程序(演示on()方法也适用于尚未创建的元素)参考:jQueryon()方法<!DOCTYPEhtml><html>
向未来的元素添加事件处理程序(演示 on() 方法也适用于尚未创建的元素)
参考:jQuery on() 方法
<html>
<head>
<script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"> script>
<script> $(document).ready(function(){ $("div").on("click","p",function(){ $(this).slideToggle(); }); $("button").click(function(){ $("This is a new paragraph.
").insertAfter("button"); }); }); script>
head>
<body>
<div style="background-color:yellow">
<p>This is a paragraph.p>
<p>Click any p element to make it disappear. Including this one.p>
<button>Insert a new p element after this buttonbutton>
div>
body>
html>
--------