jquery怎麼移除style屬性

青灯夜游
發布: 2022-05-16 15:30:14
原創
7071 人瀏覽過

在jquery中,可以利用removeAttr()方法來移除style屬性,該方法的作用就是從被選元素中移除指定屬性,只需要將該方法的的參數設為“style”即可;語法為「$(selector).removeAttr("style")」。

jquery怎麼移除style屬性

本教學操作環境:windows7系統、jquery1.10.2版本、Dell G3電腦。

style屬性是HTML核心屬性,用來為元素指定內嵌樣式(inline 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>
登入後複製

jquery怎麼移除style屬性

#【推薦學習:jQuery影片教學web前端開發影片

以上是jquery怎麼移除style屬性的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!