【发布时间】:2020-07-29 17:40:16
【问题描述】:
当点击 div 时,我需要使 div 中的 make 元素出现和消失。然后加载网页时,它应该只是说“单击此处”。单击后,在原始文本下方应出现“再次单击此处”的新文本。再次单击后,新文本出现在“再次单击”下方。再次单击后,所有文本都将被删除,并出现新的“谢谢”文本。再次单击后,该文本被删除,并出现“再见”的新文本。再次单击后,所有内容都被删除,包括文本出现的框。我是新手,真的不知道自己在做什么,我什至无法在 div 时弹出警报消息被点击,看起来应该很简单。这是我的html代码:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="project4.css">
<script src="prototype.js" type="text/javascript"></script>
<script src="project4.js" type="text/javascript"></script>
</head>
<body>
<div id="main" class="box">
<p id="clickHere">Click here</p>
<p id="clickHereAgain">Click here again</p>
<p id="clickOnceMore">Click once more</p>
<p id="thankYou">Thank you</p>
<p id="goodbye">Goodbye</p>
</div>
</body>
</html>
我的 javascript 代码只是尝试让警报弹出:
$(document).ready(function(){
$("div").click(function(){
alert("The paragraph was clicked.");
});
});
还有我的css代码:
.box {
background-color: green;
color: white;
width: 300px;
height: 200px;
padding: 10px;
text-align: center;
font-size: 30px;
}
【问题讨论】:
-
你使用的是 Prototype 还是 jQuery?
-
我的错,我正在使用原型。我试图在网上环顾四周并弄清楚如何做到这一点而感到困惑。这是prototype.js ajax.googleapis.com/ajax/libs/prototype/1.7.3.0/prototype.js
-
这看起来像 jQuery 代码。例如,
$(document).ready是 jQuery 的东西,而不是 Prototype 的document.observe。 -
好的,谢谢,我很困惑,一直在尝试使用 jquery 的东西哈哈。我现在开始取得一些进展,我让页面加载只有消息“单击此处”,并且可以在单击后添加消息“再次单击此处”,但我不知道如何制作为第二次、第三次、第四次等点击做一些不同的事情。每次单击时它都会不断添加“再次单击此处”。
标签: javascript html prototypejs