//获得和设置内容使用 text()、html() 以及 val()
//text()、html() 以及 val() 的回调函数
$(document).ready(function(){
$("#btn1").click(function(){
$("#test1").text(function(i,origText){
return "Old text: " + origText + " New text: Hello world! (index: " + i + ")";
});
});
$("#btn2").click(function(){
$("#test2").html(function(i,origText){
return "Old html: " + origText + " New html: Hello <b>world!</b> (index: " + i + ")";
});
});
});
//获取和设置元素的属性值的方法 attr() ,data()
//attr()的基本演示
$("button").click(function(){
$("#w3s").attr({
"href" : "http://www.w3school.com.cn/jquery",
"title" : "W3School jQuery Tutorial"
});
});
//attr() 的回调函数
$("button").click(function(){
$("#w3s").attr("href", function(i,origValue){
return origValue + "/jquery";
});
});
jq获取元素的内容和属性
最新推荐文章于 2022-09-28 21:47:16 发布