搜尋
首頁web前端前端問答jquery怎麼去掉body背景圖片

去掉body背景圖片的方法:1、用css(),語法「$("body").css("background","none");」;2、用attr(),語法“$("body").attr("style","background:none");”。

jquery怎麼去掉body背景圖片

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

jquery去掉body背景圖片的方法

#方法1:使用css()

css() 方法傳回或設定符合的元素的一個或多個樣式屬性。

利用css() 方法直接為background屬性新增值“none”,設定新樣式即可。

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<style>
			body{
				background: url(img/2.png) no-repeat;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("body").css("background","none");
				});
			});
		</script>
	</head>

	<body>
		<button>去掉body背景图片</button>
	</body>
</html>

jquery怎麼去掉body背景圖片

方法2:使用attr()

使用attr()設定style屬性,新增background:none 樣式,覆蓋舊樣式。

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-1.10.2.min.js"></script>
		<style>
			body{
				background: url(img/2.png) no-repeat;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function() {
				$("button").click(function() {
					$("body").attr("style","background:none");
				});
			});
		</script>
	</head>

	<body>
		<button>去掉body背景图片</button>
	</body>
</html>

jquery怎麼去掉body背景圖片

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

以上是jquery怎麼去掉body背景圖片的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
掌握CSS選擇器:高效樣式的類別與ID掌握CSS選擇器:高效樣式的類別與IDMay 16, 2025 am 12:19 AM

使用類選擇器和ID選擇器取決於具體用例:1)類選擇器適用於多元素、可重用樣式,2)ID選擇器適用於唯一元素、特定樣式。類選擇器更靈活,ID選擇器處理速度更快但可能影響代碼維護性。

HTML5規範:探索關鍵目標和動機HTML5規範:探索關鍵目標和動機May 16, 2025 am 12:19 AM

keykeygoalsandmotivationsbehindhtml5weretoenhancesemantstructure,Improvemultimediasupport,andensureBetterperformanceandCompatibalityAcroscaroscaroscaroscarossdecrossdecrossdecrossdecrossdecrossdecrossdecrossdevices,drivendybytheneedtoAddresshtml4'slimitationsand limitiTations and limittations andmeetmeetModerntructAndmmoderntructss.1)

CSS ID和類:簡單指南CSS ID和類:簡單指南May 16, 2025 am 12:18 AM

IDSareNiqueAndusedForsingLelement,andleclassEsareSareSarereableFormultIllets.1)useIdIdSforuniqueElementsLikeAspeCificheader.2)useclassesforconsistentSistentSistentStyAcroSsmultipleLementslike.3)becautiouswithspecificitifieCificityAsiseSesses.4)

HTML5目標:了解規範的關鍵目標HTML5目標:了解規範的關鍵目標May 16, 2025 am 12:16 AM

html5aimstoenhancewebaccctible,互動性和效率。 1)ITSupportsMultimediawithOutPlugins,Simplifyinginguserexperience.2)Semanticmarkmarksmarkupimprovissupimprovessupstructureandacccessessible.3)增強bacegencementingIncrassubility.4)

使用HTML5難以實現其目標嗎?使用HTML5難以實現其目標嗎?May 16, 2025 am 12:06 AM

html5isnotparticulllydifficulttousebutrequirequireSustingingItsFeatures.1)smanticelementslike like ,,,和iMproveructure,andimprovucture,可讀性,seo和acctibility.2)多中性倍增量,且可讀性

CSS:我可以在同一DOM中使用多個ID嗎?CSS:我可以在同一DOM中使用多個ID嗎?May 14, 2025 am 12:20 AM

No,youshouldn'tusemultipleIDsinthesameDOM.1)IDsmustbeuniqueperHTMLspecification,andusingduplicatescancauseinconsistentbrowserbehavior.2)Useclassesforstylingmultipleelements,attributeselectorsfortargetingbyattributes,anddescendantselectorsforstructure

HTML5的目的:創建一個更強大,更容易訪問的網絡HTML5的目的:創建一個更強大,更容易訪問的網絡May 14, 2025 am 12:18 AM

html5aimstoenhancewebcapabilities,Makeitmoredynamic,互動,可及可訪問。 1)ITSupportsMultimediaElementsLikeAnd,消除innewingtheneedtheneedtheneedforplugins.2)SemanticeLelelemeneLementelementsimproveaCceccessibility inmproveAccessibility andcoderabilitile andcoderability.3)emply.3)lighteppoperable popperappoperable -poseive weepivewebappll

HTML5的重要目標:增強網絡開發和用戶體驗HTML5的重要目標:增強網絡開發和用戶體驗May 14, 2025 am 12:18 AM

html5aimstoenhancewebdevelopmentanduserexperiencethroughsemantstructure,多媒體綜合和performanceimprovements.1)SemanticeLementLike like,和ImproVereAdiability and ImproVereAdabilityActibility.2)and tagsallowsemlessallowseamelesseamlessallowseamelesseamlesseamelesseamemelessmultimedimeDiaiaembediiaembedplugins.3)。 3)3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境