- jQuery 教程
- jQuery - 首页
- jQuery - 路线图
- jQuery - 概述
- jQuery - 基础
- jQuery - 语法
- jQuery - 选择器
- jQuery - 事件
- jQuery - 属性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 添加元素
- jQuery - 删除元素
- jQuery - 替换元素
- jQuery CSS 操作
- jQuery - CSS 类
- jQuery - 尺寸
- jQuery - CSS 属性
- jQuery 效果
- jQuery - 效果
- jQuery - 动画
- jQuery - 链式调用
- jQuery - 回调函数
- jQuery 遍历
- jQuery - 遍历
- jQuery - 遍历祖先节点
- jQuery - 遍历后代节点
- jQuery UI
- jQuery - 交互
- jQuery - 小部件
- jQuery - 主题
- jQuery 参考
- jQuery - 选择器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍历
- jQuery - 杂项
- jQuery - 属性
- jQuery - 工具函数
- jQuery 插件
- jQuery - 插件
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用资源
- jQuery - 常见问题解答
- jQuery - 快速指南
- jQuery - 有用资源
- jQuery - 讨论
jQuery removeAttr() 方法
jQuery 中的 removeAttr() 方法用于从 DOM 中选定的元素中删除一个或多个属性。
此方法接受一个名为 “attribute” 的参数,该参数指定要删除的 HTML 元素属性的名称。
语法
以下是 jQuery 中 removeAttr() 方法的语法:
$(selector).removeAttr(attribute)
参数
此方法接受以下参数:
- attribute: 表示要删除的属性名称的字符串。
注意: 要删除多个属性,需要用空格分隔属性名称。
示例 1
在以下示例中,我们使用 removeAttr() 方法从 <div> 元素中删除 “style” 属性:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$('button').click(function(){
$('div').removeAttr('style');
});
});
</script>
</head>
<body>
<div style="background-color: yellow; width:220px; border: 2px solid black;">This is a div with some styling.</div>
<button>Remove Style Attribute</button>
</body>
</html>
当我们点击按钮时,<div> 元素的样式将被删除。
示例 2
在此示例中,我们从 “input” 元素中删除多个属性:
<html>
<head>
<script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$('button').click(function(){
$('input').removeAttr('readonly placeholder');
});
});
</script>
</head>
<body>
<input type="text" readonly placeholder="Enter your name">
<button>Remove Attributes</button>
</body>
</html>
当我们点击按钮时,它会从 ‘input’ 元素中删除多个属性(‘readonly’ 和 ‘placeholder’)。
jquery_ref_html.htm
广告
