Javascript提示不断出现
Javascript Prompt keeps appearing
本文关键字:提示 Javascript 更新时间:2023-10-15
在提示中输入值后的前夜,询问"输入盎司数"的提示不断出现。。。。我该怎么做才能删除循环提示。。。我只需要它出现一次。
<html>
<body>
<script type="text/javascript">
//
// ******************************
// Program: LAB3ALT.htm
// Created by: Tanner DiBella
// Date: February 10, 2015
// Function: Convert Ounces to Pounds
// *******************************
//
/*
The Ounce to Pounds formula: 1 ounce = 0.0625 pounds
*/
var i=0;
while (i<=0) {
var ounces = prompt("Enter number of Ounces" , "1");
if (ounces==null) { /* Test for cancel */
i="1";
}
else {
var pounds= ounces * 0.0625; /* Compute number of pounds */
document.write("<BR>","Ounces : ",ounces);
document.write("<BR>","Pounds : ",pounds);
document.write("<BR>");
}
}
</script>
</body>
</html>
在else
内部,需要设置i>0
。那就行了。
尽管如此,这里还是很混乱。你想做什么?一个更简单的版本是
while(true){ //It will repeat indefinitely unlesss you break out of it
var ounces = prompt("Enter number of Ounces: " , "0");
if (ounces != null) { //Checks if user cancelled, if yes, it reappears
var pounds= ounces * 0.0625; /* Compute number of pounds */
document.write("<BR>","Ounces : ",ounces);
document.write("<BR>","Pounds : ",pounds);
document.write("<BR>");
break; //when criteria is met, you break out of the loop
}
}
相关文章:
- 提示使用服务器端事件处理程序激活JavaScript
- Javascript 可选类型提示
- 单击按钮后启动javascript提示
- 如何在 JavaScript 和 HTML 中更改对输入框的提示响应
- 使用CSS/JavaScript更改剑道图工具提示文本颜色
- 将javascript应用程序迁移到使用AMD的提示(例如requirejs)
- 通过提示中的循环触发iFrame中的输入按钮(JavaScript)
- 如何强制用户在javascript提示中输入值
- 如何在seleniumwebdriver中执行javascript提示并等待接受输入
- 在不使用javascript的情况下,可以在表单字段中设置文本占位符(以提示最终用户插入特定格式)
- 带有关闭按钮的javascript/jquery响应工具提示
- Google图表HTML工具提示,其中包含javascript onclick事件
- 在工具提示Javascript中插入HTML
- 添加一个不带jquery的工具提示-Javascript
- 工具提示JavaScript在未给出“title”属性时会中断以下表单元素
- 获取被用户终止的“提示”;javascript例外
- 验证提示javascript
- 如何修改我的工具提示javascript
- jQuery占位符/提示JavaScript保持提示的焦点
- 工具提示Javascript旋转不工作