我在指向选择框的 PHP 页面上用 javascript 编写 函数
时遇到问题。这个if语句是指向选择框
if (!(document.getElementById("add_product").value)==="Choose here")
代码如下:
function promptEnrollmentMonth() {
if (!(document.getElementById("add_product").value)==="Choose here") {
var month = prompt("Is this the correct month for this course/product?", "<?php echo "$EnrollmentMonth"; ?>");
if (month !=null) {
}
}
}
<button type="submit"
onclick="promptEnrollmentMonth()">Update</button>
<div>Add course/product:<select name='add_product'>
<option selected>Choose here</option>
<option>Other options...</option>
</select></div>
最佳答案
第一个问题是 "<?php echo "$EnrollmentMonth"; ?>"
应该是这样的:
var month = prompt("Is this the correct month for this course/product?", "<?php echo $EnrollmentMonth; ?>");
第二 <option selected>Choose here</option>
您还没有为选项标签提供值属性:
<option value='Choose here' selected>Choose here</option>
关于javascript - If语句在javascript函数中的选择框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44666480/