使用选择框使用JQuery隐藏元素
我试图让ID为articleNnumber的tr隐藏自己,直到从ID为type的select中选择更新或澄清。我在这里找到了几个不同的jquery示例,但我始终无法让它工作,决定寻求帮助使用选择框使用JQuery隐藏元素,jquery,html,Jquery,Html,我试图让ID为articleNnumber的tr隐藏自己,直到从ID为type的select中选择更新或澄清。我在这里找到了几个不同的jquery示例,但我始终无法让它工作,决定寻求帮助 <form id="test"> <table id="article"> <tr> <th>Name:</th> <td
<form id="test">
<table id="article">
<tr>
<th>Name:</th>
<td><input type="text" name="name" placeholder="Frist and Lastname" /></td>
</tr>
<tr>
<th>Account:</th>
<td><select name="client">
<option value="">Select an Account:</option>
<option value="test1">test 1</option>
<option value-"test2">test</option>
</select>
</td>
<tr>
<th>Type:</th>
<td><select id="type">
<option value="">Select One...</option>
<option value="new">New</option>
<option value="update">Update</option>
<option value="clarify">Clarification</option>
</select>
</td>
<tr id="articleNumber">>
<th>Article Number:</th>
<td><input type="text" name="article" placeholder="Enter Article" /></td>
</tr>
<tr>
</tr>
</table>
</form>
我假设如果用户切换到不进行更新或澄清,您也希望隐藏此元素 从隐藏articleNumber开始
是的,这是可能的,默认情况下隐藏文章行并使用以下js代码
$('select').on('change', function() {
if($(this).val()!='new'){
$("#articleNumber").show();
}else{
$("#articleNumber").hide();
}
});
欢迎来到SO!你可以发布一些你认为可以帮助你实现这一点的示例代码吗?你有一些无效的html只是一目了然-例如tr没有关闭。谢谢你,先生,我对jquery或javascript帮助不大。我理解代码,但很难从抓痕写入它。这不考虑是否包含其他项目。OP指定显示是否更新或澄清
$(function(){
$('#type').change(function() {
if($(this).val() === 'update' || $(this).val() === 'clarification') {
$('#articleNumber').show();
} else {
$('#articleNumber').hide();
}
});
});
$('select').on('change', function() {
if($(this).val()!='new'){
$("#articleNumber").show();
}else{
$("#articleNumber").hide();
}
});