我有一个小脚本,可以对两个隐藏的输入字段进行多次检查:
function checkfs()
{
var rating1 = (document.getElementById("rating").value);
var rating2 = (document.getElementById("rating").value);
var rating3 = (document.getElementById("rating").value);
var check1 = (document.getElementById("countpl").value);
var check2 = (document.getElementById("countpl").value);
var check3 = (document.getElementById("countpl").value);
if (rating3 == 3 && check3 > 22 || check3 < 19){
alert("message 1");
window.location.href = 'myteam.php';}
else if (rating2 == 2 && check2 > 21 || check2 < 18){
alert("message 2");
window.location.href = 'myteam.php';}
else if (rating1 == 1 && check1 > 20 || check1 < 17){
alert("message 3");
window.location.href = 'myteam.php';}
else {return true;}
}
window.onload = checkfs;
HTML
<input name="countpl" id="countpl" type="hidden" value="<?php echo $row_checkfs['count(f_player.id)']; ?>"/>
<input name="rating" id="rating" type="hidden" value="<?php echo $row_checkfs['rating']; ?>"/>
我无法理解如何根据已进行的控制类型来可视化正确的警报。目前我总是看到“alert(“message 1”)”,无论发现了什么问题。如果 rating3 == 3 && check3 > 22 || 我希望消息 1 出现 check3 < 19,如果 rating2 == 2 && check2 > 21 则显示消息 2 || check2 < 18 等。如何修改代码以获得此结果?