33.jQuery的常用方法
2018-06-12 本文已影响0人
若愚同学
$(function() {
//获取jQuery中DOM元素的个数
console.log($("#h1"));
console.log($("#h1").length);
console.log($("#h1").size());
//获取操作元素的value属性值
console.log($("#username").val());
//设置id为username的值为林小书
$("#username").val("林小书");//直接给值则是修改value
console.log($("#username").val());
//对比元素中内容和纯文本的区别
console.log($("#h1").html());//会把元素内部的标签一起打出来
console.log($("#h1").text());//只会将纯文本打印出来
//把id为h1元素的内容改成黄色
$("#h1").css("color","red");
});