我今天有一個問題,當向HTML5 DOM對象添加一個類時。對不起,如果這是一個新手問題。 :P 例如:jQuery:addClass到HTML5 DOM
<!DOCTYPE html>
<html>
<head>
<title>stackoverflow example</title>
<style>
.centercontent {
width:100%;
max-width:1080px;
margin:0 auto;
}
</style>
</head>
<body>
<header>
<!-- All direct children of BODY should be centered on the page; however, children should not be added to .centercontent -->
<h1>Site Name</h1>
</header>
<section>
<p>Hello World</p>
</section>
<footer>
© no one 2012
</footer>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.j"></script>
<script>
$("body > *").addClass("centercontent");
</script>
</html>
我相信這是我的JS;不過,我從來沒有使用過addClass。非常感謝你的時間。 :) 祝你有美好的一天!
你正在引用jQuery缺少結尾s,它是'src =「http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.j」'但應該是' src =「http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js」' – 2012-07-25 15:02:17
如果你使用瀏覽器開發工具,你可能會像'$未定義' 。 – 2012-07-25 15:06:21