属性
1.属性
1.1 attr(name|properties|key,value|key,fn)
1) 获取属性值 $("img").attr("src");
2) 设置属性值 $("img").attr("title","你好");$("img").attr({src:"img1.png",alt:"img1"})
3) 设置属性值 $("img").attr("alt",function(index,value){return value + index}) //index为当前元素的索引,value为"alt"原先的属性值
1.2 removeattr(name)
删除一个属性 $("img").removeattr("alt");
1.3 prop(name|properties|key,value|key,fn)
$("input[type='checkbox']").prop("checked", true);
$("input[type='checkbox']").prop("checked", function( i, val ) { return !val; });
1.4 removeprop(name)
用来删除由.prop()方法设置的属性集
1.5 attr() 与 prop() 的区别
具有 true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()
2.css类
2.1 addclass(class|fn)
$("p").addclasss("active focus");
$("ul li").addclass(function(i,class){return class+i})
2.2 removeclass([name|fn])
$("p").removeclass("active");
$("p").removeclass(function(){return $(this).attr("class")})
2.3 toggleclass(class|fn)
$("p").toggleclass("active");
$(".class").toggleclass(function(){
if($(this).parent().is(".myclass"))
{
return "classone";
}
else
{
return "classtwo";
}
})
3.html代码|文本|值
3.1 html([val|fn])
获取内容 $("div").html() 取得第一个匹配元素的html内容
设置内容 $("div").html("
htmlhtmlhtml
");以上就是jQuery属性与CSS操作的内容,更多相关文章请关注PHP中文网(www.php.cn)!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号