如何切换动态 ID 表的显示?
我有一个根据下拉列表选项显示行的表。行是动态创建的。我使用 ddl 上的值作为初始行,然后使用一个简单的计数器来使其唯一。有没有办法说显示所有以“tableShoes”开头的行,即使这些行类似于tableShoes1、tableShoes2等?
$('#itemSelect').change(function() {
var item = $('#itemSelect').val();
$('#itemList tr').each(function() {
$(this).hide();
});
$('#' + item + 'Header').show();
$('#' + item + '1').show();
//Because the table is dynamic, I am not sure how many
//rows would be available so I only see the first option.
});
I have a table that displays rows based on a drop down list option. The rows are dynamically created. I use the value on the ddl for the initial row, then a simple counter to make it unique. Is there a way to say something like show all the rows that start with "tableShoes" even though the rows are something like tableShoes1, tableShoes2, etc?
$('#itemSelect').change(function() {
var item = $('#itemSelect').val();
$('#itemList tr').each(function() {
$(this).hide();
});
$('#' + item + 'Header').show();
$('#' + item + '1').show();
//Because the table is dynamic, I am not sure how many
//rows would be available so I only see the first option.
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议在添加每行时添加相同的 CSS 类名,也许与所选项目的值相同。这样你的最后一行就可以是:
而且你不必担心索引。
I would suggest adding the same CSS class name to each row as it is added, perhaps the same as the value of the selected item. That way your last line could just be:
And you wouldn't have to worry about the index.
这个选择器应该解决你的问题: $('[id|=tableShoes]')
this selector shoud solve your problem: $('[id|=tableShoes]')