gpt4 book ai didi

javascript - 将所选选项值与 php 变量进行比较

转载 作者:行者123 更新时间:2023-11-28 19:58:42 25 4
gpt4 key购买 nike

我的 php 代码中的选项列表如下:

<select class="form-control" name="currentDegree" id="currentDegree">
<option value="Junior High School">Junior High School</option>
<option value="Senior High School">Senior High School</option>
<option value="Diploma">Diploma</option>
<option value="Bachelor Degree">Bachelor Degree</option>
<option value="Master">Master</option>
<option value="Doctor">Doctor</option>
</select>

然后JS标记为

<script>
var currentDegree = $('#currentDegree').val(); // selected option at listbox
var minimumDegree = '<php? echo $minimumDegree; ?>'; // it come from the admin backend
var md; // dinamic variable ( condition depend on minimumDegree )

function CheckDegree(){

if (minimumDegree == 'Junior High School') {
md = 0;
} else if (minimumDegree == 'Senior High School') {
md = 1;
}
else if (minimumDegree == 'Diploma') {
md = 2;
}
else if (minimumDegree == 'Bachelor Degree') {
md = 3;
}
else if (minimumDegree == 'Master') {
md = 4;
}
else (minimumDegree == 'Doctor') {
md = 5;
}
};
// Compare the currentDegree variable with External variable
if (parseint(currentDegree) < md) {
alert(" Current degree is less than Our minimum requirement !");
return false;
}
</script>

我在提交时使用 onclick="CheckDegree()",但似乎无法正常工作,有谁知道JS代码中的错误类型是什么

谢谢

最佳答案

尝试使用:

var minimumDegree =  '<?php echo $minimumDegree; ?>';

而不是:

var minimumDegree = '<php? echo $minimumDegree; ?>';

您需要<?php不是<php?

关于javascript - 将所选选项值与 php 变量进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22061285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com