jsjquery怎么移除已添加的属性?

jsjquery怎么移除已添加的属性?,第1张

以下二种方法是可以为input添加disabled属性的方法:

//两种方法设置disabled属性

$('#areaSelect').attr("disabled",true)

$('#areaSelect').attr("disabled","disabled")

以下三种方法是移除(去除)掉input的disabled属性的方法:

//三种方法移除disabled属性

$('#areaSelect').attr("disabled",false)

$('#areaSelect').removeAttr("disabled")

$('#areaSelect').attr("disabled","")

将style中你想删掉的属性设为null应该是可以解决的,Chrome通过

例如:

elem.style["height"] = null//彻底删除elem的style属性的height值

<!DOCTYPE HTML>

<html>

<head>

<meta charset="UTF-8" />

<title>last.html</title>

<style>

</style>

<script type="text/javascript">

var change = function ()

    {

    var a = document.getElementById ('a')

    a.value = 'apple'

    for ( var i = 0 i < a.children.length i++)

    {

    var ac = a.children[i]

    if (!!ac.getAttribute ('selected'))

    {

    ac.removeAttribute ('selected')

    }

    if (ac.value == 'apple')

    {

    ac.setAttribute ('selected', 'selected')

    }

    }

    }

</script>

</head>

<body>

<select id="a">

<option value="apple">苹果</option>

<option value="orange" selected="selected">橘子</option>

<option value="pear">雪梨</option>

</select>

<input type="button" onclick="change()" value="change" />

</body>

</html>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/8007627.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存