0
我试图根据选定的值在下拉菜单中显示和隐藏行。用户选择user_name
后,我可以使用按钮在表格中隐藏该用户行,但是我希望在选择后显示并隐藏行,而不必单击按钮,我无法使其工作。使用jquery函数和下拉列表选择
这是一个按钮,我的工作功能:
$(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,我们可以更容易地帮你 – dave 2015-02-11 16:06:28
你是指'$(“。selectedName”).change()'还是'$(“#selectedName”)。第二个代码片段? – 2015-02-11 16:06:48