<!DOCTYPE html><html><head><script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script>$(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 + ")";});});});</script></head><body><p id="test1">This is a <b>bold</b> paragraph.</p><p id="test2">This is another <b>bold</b> paragraph.</p><button id="btn1">Show Old/New Text</button><button id="btn2">Show Old/New HTML</button></body></html>
1 回答

繁華開滿天機(jī)
TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊
<!DOCTYPE html> < html > < head > < script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" > </ script > < script > $(document).ready(function(){ $("#btn1").click(function(){ $(".test1").text(function(i,origText){ return "Old text: " + origText + " New text: Hello world! (index: " + i + ")"; }); }); $("#btn1").click(function(){ $(".test1").html(function(i,origText){ return "Old text: " + origText + " New text: Hello world! (index: " + i + ")"; }); }); }); </ script > </ head > < body > < p class = "test1" >This is a < b >bold</ b > paragraph.</ p > < p class = "test1" >This is another < b >bold</ b > paragraph.</ p > < button id = "btn1" >Show Old/New Text</ button > < button id = "btn2" >Show Old/New HTML</ button > </ body > </ html > |
添加回答
舉報(bào)
0/150
提交
取消