欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您的位置:DIVCSS5首页 > HTML >
  .removeAttr( attributeName )
  
  描述: 为匹配的元素集合中的每个元素中移除一个属性(attribute)。
  
  .removeAttr() 方法使用原生的 JavaScript removeAttribute() 函数,但是它的优点是可以直接在一个 jQuery 对象上调用该方法,并且它解决了跨浏览器的属性名不同的问题。
  
  注意: Internet Explorer 6, 7 ,或8中,使用.removeAttr()删除一个内联onclick 事件处理程序没有实现,为了避免潜在的问题,使用 .prop()代替:
  
  $element.prop("onclick", null);
  
  console.log("onclick property: ", $element[0].onclick);
  
  例子:
  
  点击按钮,添加或删除按钮后面 input 元素的 title 属性。
  
<!DOCTYPE html>
<html>
<head>
  <script src="https://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button>Enable</button>
<input type="text" title="hello there" />
<div id="log"></div>
 
<script>
(function() {
  var inputTitle = $("input").attr("title");
  $("button").click(function () {
    var input = $(this).next();
 
    if ( input.attr("title") == inputTitle ) {
      input.removeAttr("title")
    } else {
      input.attr("title", inputTitle);
    }
 
    $("#log").html( "input title is now " + input.attr("title") );
  });
})();
</script>
 
</body>
</html>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h63997.shtml

如对文章有任何疑问请提交到DIV CSS论坛,或有任何网页制作CSS问题立即到CSS论坛发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。
CSS教程文章修订日期:2018-08-14 17:37 原创:DIVCSS5
本文www.divcss5.com DIVCSS5版权所有。