0

我有两个下拉选择。一个叫做 Disciplines,另一个叫做 MensLevels 它们都基于第一个选择的值共享相同的 ID,我如何隐藏第二个选择?这是我的代码:

    $("select[name=Disciplines]").change(function() {
        if ($(this).val() == 'Acro') {
                var PID = $(this).attr('id');
                $('td:nth-child(6).attr("id") == "' + PID + '"').hide(); 
            }
    });
4

2 回答 2

1
$("select[name=Disciplines]").change(function () {
    if ($(this).val() == 'Acro') {
        $('select[name=MensLevels][id="' + this.id + '"]').hide();
    }
});
于 2013-05-08T14:44:50.197 回答
1

首先,.change事件选择器中的值 "Disciplines" 必须像这样在其周围加上引号:"select[name='Disciplines']" 而不是没有引号的方式:"select[name=Disciplines ]"

这可能是你要找的吗?:

$("select[name='Disciplines']").change(function() {
    if ($(this).val() == 'Acro') {
            var PID = $(this).attr('id');


            $('#' + PID).each(function(index){
                if(index > 0 && $(this).attr("name") != "Disciplines"){
                   $(this).hide();
                   return true;
                }
            });
        }
});
于 2013-05-08T14:36:28.143 回答