[英]How do you put a string variable in the confirm() function in Javascript/HTML?
我正在嘗試與用戶確認他或她將要輸入的以下字符串是否正確但是不會出現確認框。 這是代碼的一部分:
<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}
它工作正常但它不包括用戶的輸入,這不是我不想實現的。 有幫助嗎? 謝謝!
像這樣編輯:
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.