【问题标题】:Passing the input value of prompt boxes传递提示框的输入值
【发布时间】:2012-05-26 14:03:36
【问题描述】:

可以这样传递提示框的输入值吗?

<script type="text/javascript">
function prompt_box()
{
var naam=prompt("Please enter your name:","Type your name here.")
document.location = 'delete.php?target=' + naam;
}
</script>

或者我必须使用表格吗?

【问题讨论】:

  • “这个”是什么意思?该代码对我来说很好。
  • 弹出窗口可能会影响用户体验......但它会起作用!
  • 你有没有亲自尝试过它是否有效?答案是肯定的。

标签: javascript input popup prompt


【解决方案1】:

这是将prompt返回的值传递给变量的正确方法。

var value = prompt("Please enter your name:", "Type your name here.");

【讨论】:

  • 感谢它的工作。我认为在我的初始代码中解析有问题。还是谢谢。
【解决方案2】:

如果您使用 javascript 创建一个窗口提示,它会要求您输入一些内容。所以你必须以这种方式实现你的代码才能得到提示,

<html>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var name = prompt("Please enter your name", "Micheal");
  if (name != null) {
    document.getElementById("demo").innerHTML =
    "Hello " + name + "! How are you today?";
  }
}
</script>

</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    相关资源
    最近更新 更多