我有一些元素,例如 TextBox
、Select
。我有一个脚本来隐藏一些元素。为此,我使用下面的代码,但它不起作用:
$(document).on('change', '#TypeId', function (e) {
var selected = $(this).val();
if (selected == 1) {
$($('#Issue').parent(), $('#ServiceRequestId').parent()).hide();
console.log('test');
}
});
它只是隐藏了第一个选择器。当我像下面这样更改选择器时,它工作正常:
$( $('#ServiceRequestId').parent()).hide();
最佳答案
second argument is the context在 jQuery 中,这将有助于在该上下文中过滤元素。
我想你想结合这两个对象,为此使用 add()
组合两个独立的 jQuery 对象的方法。
$('#Issue').parent().add($('#ServiceRequestId').parent()).hide();
或同时提供 jQuery objects within an array .
$([$('#Issue').parent(), $('#ServiceRequestId').parent()]).hide()
关于javascript - 如何在 jQuery 中选择一些元素作为选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41804551/