• 技术文章 >web前端 >前端问答

    jquery怎么移除style属性

    青灯夜游青灯夜游2022-05-16 15:30:14原创1875

    在jquery中,可以利用removeAttr()方法来移除style属性,该方法的作用就是从被选元素中移除指定属性,只需要将该方法的的参数设置为“style”即可;语法为“$(selector).removeAttr("style")”。

    本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。

    style属性是HTML核心属性,用于为元素指定内联样式(inline style)。

    style属性将覆盖其他全局样式,比如在<style>元素或外部样式表中定义的样式。

    那么利用jquery怎么移除style属性

    在jquery中,可以利用removeAttr()方法来移除style属性。

    removeAttr() 方法用于从被选元素中移除属性。

    语法:

    $(selector).removeAttr(attribute)

    attribute:必需。规定从指定元素中移除的属性。

    示例:移除第一个 p 元素的style属性

    <!DOCTYPE html>
    <html>
    
    	<head>
    		<meta charset="UTF-8">
    		<script src="js/jquery-1.10.2.min.js"></script>
    		<script type="text/javascript">
    			$(document).ready(function() {
    				$("button").click(function() {
    					$("p:first").removeAttr("style");
    				});
    			});
    		</script>
    
    	</head>
    
    	<body>
    		<h1>这是一个大标题</h1>
    		<p style="font-size: 120%;color: blue;background-color: yellow;">这是一个段落。</p>
    		<p style="font-size: 120%;color: blue;background-color: yellow;">这是另一个段落。</p>
    		<button>移除第一个 p 元素的style属性</button>
    	</body>
    
    </html>

    1.gif

    【推荐学习:jQuery视频教程web前端开发视频

    以上就是jquery怎么移除style属性的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:jquery style属性
    上一篇:jquery怎么让文本框不可编辑 下一篇:jquery select()方法怎么用
    20期PHP线上班

    相关文章推荐

    • 【活动】充值PHP中文网VIP即送云服务器• jquery怎样设置数组转字符串• jquery中除法怎样取小数点后两位• css和jquery有什么区别• jquery怎样判断是否包含某个id元素• jquery怎么隐藏某个div• jquery怎么判断指定子元素是否存在
    1/1

    PHP中文网