<button>按钮</button> <div>我是div</div> $('button').click(function () { $('div').toggleClass('hide'); }); 3、尺寸 width() 方法描述:获取内容元素width的值。 height() 方法描述:获取内容元素height的值。 innerWidth() 方法描述:获取内容元素width+padding的值。 innerHeight() 方法描述:获取...
$(document).ready(function(){$("button").click(function(){varid=$(this).data("id");console.log(id);});}); 1. 2. 3. 4. 5. 6. 在这个例子中,我们通过使用click事件处理程序来监听button元素的点击事件。在点击事件发生时,我们使用data()方法来获取button中data-id属性的值,并将其打印到浏览...
// 点击按钮时获取特殊属性节点值$("button").click(function(){vardataId=$(this).attr("data-id");console.log(dataId);}); 1. 2. 3. 4. 5. 在上面的代码中,我们首先通过$("button")选择器获取所有的按钮元素,然后使用.click()方法来绑定点击事件。在点击事件的回调函数中,我们使用$(this)来获取...
<html><head><scriptsrc="./jquery.js"></script></head><body><divname="template"><inputtype="button"id="testBtn"value="click me"></div><script>functionsayHi() { alert("hi") } document.getElementById("testBtn").onclick=sayHi;</script></body></html> 第三种方法, 是使用通用的事件...
functiongreet(event){ alert("Hello "+ event.data.name ); } $("button").on("click", { name:"Karl" }, greet ); $("button").on("click", { name:"Addy" }, greet ); The above code will generate two different alerts when the button is clicked. ...
$("button").on("click",function(){ $("p").show("slow"); }); </script> </body> </html> Demo: Show the first div, followed by each next adjacent sibling div in order, with a 200ms animation. Each animation starts when the previous sibling div's animation ends. ...
$(document).ready(function(){$("button").click(function(){$("p").hide();});}); #id 选择器 jQuery #id 选择器通过 HTML 元素的 id 属性选取指定的元素。页面中元素的 id 应该是唯一的,所以您要在页面中选取唯一的元素需要通过 #id 选择器。
<div id="demo"><pclass="text-info">hello world</p><input type="text"name="user"value="hello world"></div><button id="btn">点我</button><script>$(document).ready(function(){$("#btn").click(function(){// 添加一个元素$("p.text-info").replaceWith("<p>替换成新文本</p>")...
Upgrade Your Browser Your web browser (Internet Explorer) is looking a little retro.Try one of these to have a better experience on Zoho Desk. Use latest three version for below mentioned browsers
$('#hideButton').click(function() { $('#myImage').hide(); }); });</script></body></html> 4. 如何隐藏图片? 当用户在页面上点击按钮时,jQuery 代码会监听到按钮点击事件,然后找到 ID 为myImage的图片元素,并调用.hide()方法将其隐藏起来。这样,当用户点击按钮时,图片就会从页面中消失。