當按下按鈕時,我想另一個div標籤出現在用戶的屏幕上。我試過並瀏覽了很多網頁,看看哪裏出了問題。在網頁的控制檯上沒有錯誤。這裏是HTML代碼和JavaScript代碼。JQuery動態html頁面
/*jslint browser: true*/
/*global $, jQuery, alert*/
$("buttonId").click(function() {
var structure = $("<div>Hello world</div>");
$("#newDiv").append(structure);
document.getElementById("div01").style.backgroundColor = "red";
});
<html>
<head>
<link rel="stylesheet" href="site.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<nav>
<p class="logo"> Logo! </p>
<ul id="ul01">
<li><a href="#" class="active">NewsFeed</a></li>
<li><a href="#">Discover</a></li>
<li><a href="#">Following</a></li>
</ul>
<div class="logIn">
<a href="#"> Login </a>
<a href="#"> Sign Up </a>
</div>
</nav>
<a id="buttonId" href="#"> Click fo anouther div!!</a>
<div id=newDiv>
<div id=div01> Hello </div>
</div>
<script src="operations.js"></script>
</body>
</html>
'$( 「#buttonId」)'... –
'$( 「buttonId」)'會不符合你的元素。它應該是'$(「#buttonId」)' – Steve
謝謝,它現在可行 – Jack