【发布时间】:2015-05-09 05:13:46
【问题描述】:
如何去掉 onclick="clickMe()" 按钮,让提示框中的输入执行功能?
我想我需要提示框中的输入来调用 if 语句?
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<script>
function clickMe(){
var valueInput=prompt("Please input weekday, weekend?");
var weekdayElement = document.getElementById("weekday");
var weekendElement = document.getElementById("weekend");
if (valueInput=="weekday"){
weekdayElement.style.height = "200px";
weekdayElement.style.width = "250px";
weekdayElement.style.fontSize = "15px";
weekdayElement.style.color="blue";
if (valueInput=="weekend"){
weekendElement.style.height = "200px";
weekendElement.style.width = "250px";
weekendElement.style.fontSize = "15px";
weekendElement.style.color="blue";
}
</script>
</head>
<body>
<h1>This is an example on DOM</h1>
<div id="weekday">
weekdays
<p>Monday</p>
<p>Tuesday</p>
<p>Wednesday</p>
<p>Thursday</p>
<p>Friday</p>
</div>
<div id="weekend">
weekends
<p>Saturday</p>
<p>Sunday</p>
</div>
<p><button onclick="clickMe()">Try it</button></p>
</body>
</html>
【问题讨论】:
-
你的问题没有意义。
clickMe触发提示框,但您问的是如何使提示框触发clickMe。这就像要求提示框及时返回并触发自身。您可能需要重新考虑您的问题并尝试更清楚地陈述它。 -
你能再澄清一点吗?目前,此代码设置为:(1)单击按钮,(2)
clickMe()函数运行,并显示提示。 (2) 收集输入后,运行剩下的代码。您希望提示自动运行,还是没有看到规定的行为?
标签: javascript function if-statement prompt