【问题标题】:dropdown not working when clicked a second time第二次单击时下拉菜单不起作用
【发布时间】:2015-11-25 08:57:28
【问题描述】:

我的复选框有问题。如果我选择一个值并验证,我不能第二次这样做,它不起作用。查看其他问题,我发现我可能必须将 prop() 函数与“checked”属性一起使用,但它仍然无法正常工作。

这是我的网站: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>

【问题讨论】:

  • 复选框或下拉菜单?...请让您的问题更清楚..
  • 下拉我的错误,对不起
  • 感谢提供链接,但实际上我在做一些研究时看到了它,它对我不起作用
  • 非常感谢!

标签: javascript jquery html


【解决方案1】:

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

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

也不确定您是否需要此处的提交按钮。如果您需要不应该提交页面的简单按钮,请将显示按钮 type="submit" 更改为 type="button"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2014-12-26
    相关资源
    最近更新 更多