一、设置内容以及回调函数
方法
例子
$("#btn1").click(function(){ $("#test1").text("Hello world!");});//设置文本内容$("#btn2").click(function(){ $("#test2").html("<b>Hello world!</b>");});//设置元素内容$("#btn3").click(function(){ $("#test3").val("Dolly Duck");});//设置值$("#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 + ")"; });});//返回元素内容TIPS
回调函数由两个参数:被选元素列表中当前元素的下标,以及原始(旧的)值。然后以函数新值返回您希望使用的字符串。
二、设置属性以及回调函数
方法
attr() - 设置属性值
例子
$("button").click(function(){ $("#w3s").attr("href","http://" rel="external nofollow" target="_blank">百度</a></p> <input type="button" id="bt8" value="改变href值为搜索1(回调函数)" ""> </body></html>以上所述是小编给大家介绍的jQuery设置内容和属性详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!