网络编程 
首页 > 网络编程 > 浏览文章

jQuery中removeProp()方法用法实例

(编辑:jimmy 日期: 2025/5/11 浏览:3 次 )

本文实例讲述了jQuery中removeProp()方法用法。分享给大家供大家参考。具体分析如下:

此方法可以删除由prop()方法设置的属性。

语法:
复制代码 代码如下:$("selector").removeProp(name)

参数列表:
参数 描述 name 定义要要删除的属性名称。

实例:

实例一:

复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="https://www.jb51.net/" />
<head>
<title></title>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.8.3.js"> <script type="text/javascript">
    $(document).ready(function(){
       $("td").prop({width:"200",height:"300"});
       $("button").click(function(){
           $("td").removeProp("width");
       })
    })
</script>
</head>
<body>
    <table border="1">
      <tr>
       <td>欢迎来到</td>
      </tr>
    </table>
    <button>删除属性</button>
</body>
</html>

以上代码可以删除td的width属性。

实例二:

复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="https://www.jb51.net/" />
<head>
<title></title>
<style type="text/css">
   td
   {
       width:200px;
   }
</style>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.8.3.js"> <script type="text/javascript">
    $(document).ready(function(){
       $("td").prop({height:"300"});
       $("button").click(function(){
            $("td").removeProp("width");
       })
    })
</script>
</head>
<body>
    <table border="1">
      <tr>
       <td>欢迎来到</td>
      </tr>
    </table>
    <button>删除属性</button>
</body>
</html>

以上代码并没有删除td的width属性,这是因为removeProp()只能删除由prop()方法设置的属性。

希望本文所述对大家的jQuery程序设计有所帮助。

上一篇:判断浏览器的内核及版本号方法汇总
下一篇:jQuery中prop()方法用法实例
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap