【发布时间】:2015-02-11 16:01:36
【问题描述】:
我正在尝试根据下拉列表中的选定值显示和隐藏行。用户选择 user_name 后,我可以使用按钮在表中隐藏此用户行,但我想在选择后显示和隐藏行而不单击按钮,我无法让它工作。
这是我使用按钮的工作功能:
$(document).ready(function() {
$("button").click(function() {
$("td").each(function(index, paragraph) {
$td = $(paragraph);
if ($td.html() === $('select[name=select1]').val()) {
//hide the matched row rather than remove it
$(this).parent("tr:first").hide();
}
});
$('select[name="select1"]').on('change', function() {
$("tr").show();
});
});
});
这是在尝试避免使用按钮后不起作用的功能:
$(document).ready(function() {
$("selectedName").change(function() {
$("td").each(function(index, paragraph) {
$td = $(paragraph);
if ($td.html() === $('select[name=select1]').val()) {
//hide the matched row rather than remove it
$(this).parent("tr:first").hide();
}
});
$('select[name="select1"]').on('change', function() {
$("tr").show();
});
});
});
我在第二个中做错了什么?
【问题讨论】:
-
如果您也显示您的 HTML,我们会更容易为您提供帮助
-
您的意思是
$(".selectedName").change()还是第二个代码sn-p 中的$("#selectedName").change?