1,获取元素,通过name获取元素:
var boxes = $("input[name='_checkbox']:checked");
2,设置属性不成功,(在使用jquery动态设置layui的checkbox元素的选中状态时始终只能取消选中,却不能重新勾选,点击勾选则没有问题,代码如下),使用prop替换 prop即可
if (value == "true") {
//$id.attr("checked", "checked");
$id.prop("checked", true); }
else {
$id.prop("checked", false);
//$id.removeAttr("checked");
}
3,移除标签的属性
Query 提供了移除元素属性的方法,".removeAttr( String attributeName )”
移除 a 标签的title属性:
$("a").removeAttr("title");
获取属性 .getAttribute("属性") -----原生
获取属性 .attr("属性")-----jquery
*jq获取属性*/ var temp = $('.test1').attr('class'); /*js获取属性*/ var temp = document.getElementById('test1').getAttribute('data');
设置元素的属性
设置属性 .setAttribute("属性","值") 设置属性 .attr("属性","值")
/*jq设置属性*/ var temp2= $('.test2').attr('class','test-spe'); /*js设置属性*/ var temp2= document.getElementById('test2').setAttribute('data','self-name-2');
删除元素的属性
删除属性 .removeAttribute 删除属性 .removeAttr
/*jq删除属性*/ var temp = $('.test1').removeAttr('data'); /*js删除属性*/ var temp = document.getElementById('test1').removeAttribute('data');