我正在尝试与用户确认他或她将要输入的以下字符串是否正确但是不会出现确认框。以下是代码段:
<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>
我不允许在确认函数中传入字符串变量吗?因为如果我取消${pkey}
它工作正常但它不包括用户的输入,这不是我不想实现的。有帮助吗?谢谢!
答案 0 :(得分:2)
像这样编辑:
var pkey = document.forms["createPixelForm"]["pagekeyTF"].value;
var agree = confirm("Is this your product?\n\n " + pkey);