简体   繁体   English

如何在Javascript / HTML中的confirm()函数中放置一个字符串变量?

[英]How do you put a string variable in the confirm() function in Javascript/HTML?

I am trying to confirm with the user if the following string he or she is about to enter is correct but the confirmation box won't appear. 我正在尝试与用户确认他或她将要输入的以下字符串是否正确但是不会出现确认框。 Here is that segment of the code: 这是代码的一部分:

<html xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<script>
   function validateForm(){
      var pkey = document.forms["createProductForm"]["pagekeyTF"].value;
      var agree = confirm("Is this your product?\n\n ${pkey}");

      if(agree) //Do something
      else //Do something else
   }
</script>
</head>
<body>
   <form name="createProductForm" controller="actions" action="ImplementNewProduct" onsubmit="return validateForm()" method="post">

      <g:textField id="productTF" name="productTF" value="My Product" />       
      <button id="createProductID" name="createButton" value="Create Product">Create Product</button>

   </form>
</body>
</html>

Am I not allowed to pass in string variables in the confirmation function? 我不允许在确认函数中传入字符串变量吗? Because if I take off the ${pkey} it works fine but it does not include the user's input and that is not what I am not trying to achieve. 因为如果我取消${pkey}它工作正常但它不包括用户的输入,这不是我不想实现的。 Any help? 有帮助吗? Thanks! 谢谢!

Edit it like this : 像这样编辑:

var pkey = document.forms["createPixelForm"]["pagekeyTF"].value;
var agree = confirm("Is this your product?\n\n " + pkey);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM