下拉框不工作时,点击第二次

dropdown not working when clicked a second time

本文关键字:第二次 工作      更新时间:2023-09-26

我的复选框有问题。如果我选择一个值并进行验证,我不能第二次这样做,它不起作用。查看其他问题,我看到我可能必须使用带有"checked"属性的prop()函数,我这样做了,但它仍然不起作用。

这是我的网站:http://nts.nuvision.co.za/index.php/training/

这是我的javascript:

    $('#one').hide();
    $('#two').hide();
    $('#three').hide();
    $('#show').click(function() {
        $('#pgc-224-0-1').css("margin-top", "0px");
        switch(document.getElementById('trainingcourses').value) {
            case 'one':
                $('#one').show();
                $('#two').hide();
                $('#three').hide();
                $("#trainingcourses").prop('checked', false);
            break;
            case 'two':
                $('#two').show();
                $('#one').hide();
                $('#three').hide();
                $("#trainingcourses").prop('checked', false);
            break;
            case 'three':
                $('#three').show();
                $('#two').hide();
                $('#one').hide();
                $("#trainingcourses").prop('checked', false);
            break;
        }
    });
这里是我的HTML:
<form id="trainingform">
<select id="trainingcourses" style="font-size: 12pt;">
<option style="font-size: 12pt;" value="one">Sugar and Suite CRM End User Training</option>
<option style="font-size: 12pt;" value="two">Sugar & Suite CRM Advanced End User Training</option>
<option style="font-size: 12pt;" value="three">Sugar and Suite CRM Administrator : Getting Started</option>
</select><input id="show" style="margin-top: -25px; margin-left: 20px;" name="show" type="submit" value="Show more information" onclick="location.href='http://nts.nuvision.co.za/index.php/training/#' + document.getElementById('trainingcourses').value; return false;"/></form>
<div id="one"> (...) </div>
<div id="two"> (...) </div>
<div id="three"> (...) </div>

您将checked属性设置为选择无效的框。从switch case语句中删除下面的行,它应该可以工作了。

$("#trainingcourses").prop('checked', false);

也不确定这里是否需要一个提交按钮。如果你需要一个简单的按钮,不应该提交页面,然后改变显示按钮type="submit"type="button"