如何通过 jQuery text() 和 html()

  • text() - 设置或返回所选元素的文本内容
  • html() - 设置或返回所选元素的内容(包括 HTML 标记)
  • val() - 设置或返回表单字段的值
$("#btn1").click(function(){
  alert("Text: " + $("#test").text());
});

$("#btn2").click(function(){
  alert("HTML: " + $("#test").html());
});

$("#btn1").click(function(){
  alert("Value: " + $("#test").val());
});

$("button").click(function(){
  alert($("#w3s").attr("href"));
});

 

posted on 2015-04-11 10:20  潸何  阅读(219)  评论(0)    收藏  举报