layui jquery 常用表单处理方法

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');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值