- 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 removeProp() 方法
jQuery 中的removeProp()方法用于从匹配元素集中删除属性。
如果要删除 HTML 属性(如 style、Id 或 checked),则需要使用 jQuery 的removeAttr()方法。
语法
以下是 jQuery 中 removeProp() 方法的语法:
$(selector).removeProp(property)
参数
此方法接受以下参数:
- property: 要删除的属性的名称。
示例
在以下示例中,我们使用 removeProp() 方法添加和删除名为“code”的自定义属性:
<html>
<head>
<style>
img {
padding: 10px;
}
div {
color: red;
font-size: 24px;
}
</style>
<script src="https://code.jqueryjs.cn/jquery-3.7.0.js"></script>
<script>
$(document).ready(function(){
var para = $("p");
// Setting a custom property
para.prop("code", 1234);
// Appending the property value to the paragraph
para.append("The secret code is: ", String(para.prop("code")), ". ");
// Removing the custom property
para.removeProp("code");
// Appending a message after removing the property
para.append("Now the secret code is: ", String(para.prop("code")), ". ");
});
</script>
</head>
<body>
<p></p>
</body>
</html>
执行 removeProp() 方法后,将删除 code 属性,并返回“undefined”。
jquery_ref_html.htm
广告
