如何从提示窗口获取响应,并将其显示在网页上的某个位置?
我现在拥有的代码是:
<html>
<head>
<center>
<FORM>
<INPUT type="button" value="Click Me." name="button" onClick="alert('I Like Waffles')">
<INPUT type="button" value="Whats Your Favorite Food" name="button" onClick="prompt('Whats Your Favorite Food?')">
</FORM>
</center>
</head>
</html>
我想知道如何从提示符处获取响应并将其放置在html中的某个位置。
最佳答案
工作示例:
<html>
<head>
<center>
<script>
function gen(){
var a = prompt("What's your favorite food?");
document.getElementById("demo").innerHTML = a;
}
</script>
<FORM>
<INPUT type="button" value="Click Me." name="button" id="button" onClick="alert('I Like Waffles')">
<INPUT type="button" value="Whats Your Favorite Food" name="button" onClick="gen();">
<p id="demo"></p>
</FORM>
</center>
看看这个Fiddle
关于javascript - 我如何从提示中获得响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31364673/