removeAttr()

功能

从指定的元素中删除一个属性。

语法

datax.removeAttr(elm, name)

参数

  • elm
    HTMLElement对象,指定对象HTML元素
  • name
    删除一个属性

范例

Example: 查找每个含有 <em> 中的 title 属性,并显示在 <div>,点击 button 移除 title。

<!DOCTYPE html>
<html>

<head>
    <style>
  em { color:blue; font-weight:bold; }
  div { color:red; }
    </style>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.3/require.min.js"></script>
    <script>
    require.config({
        baseUrl: "./",
        packages: [
            { name: "skylark", location: "../../../src/skylark" },
        ]
    });
    </script>
</head>

<body>
<p>
  Once there was a <em title="huge, gigantic">large</em> dinosaur...
</p>
  The title of the emphasis is:<div></div>
  <button>remove title</button>
<strong></strong>
    <script>
    require(["skylark/query","skylark/finder", "skylark/datax"], function(query,finder, datax) {
        var title=datax.attr(finder.find("em"), "title");
        query("div:first").text(title);
        query("button").click(function(){
                datax.removeAttr(finder.find("em"), "title");
                var removeTitle=datax.attr(finder.find("em"), "title");
                datax.text(finder.find("strong"),removeTitle ? removeTitle : "title is null");
        });
    });
    </script>
</body>

</html>