我创建了一个名为 billingOptions() 的函数,它与下拉(选择)元素相关联。当用户在下拉列表中选择一个选项时,该函数将运行。
下拉菜单将通过页面动态添加...每次添加 billingOptions() 函数 onChange。我正在尝试使用 Jquery 从已更改的下拉列表中找到最接近的 class=rate 实例。请记住,下拉菜单是动态添加的,因此可能有很多 .rate ...
我曾尝试使用“this”和“closest”来查找最近的类(我什至不确定您是否可以使用具有最接近功能的类)。这是一些代码:
***我被要求提供 HTML 的确切结构(表格的行是动态生成的。表格是静态的)。
<table id="billTasks">
<tr> <input class="taskNameInput" type="text" size="52" placeholder="Task Name" name="task:1" disabled="disabled"> <select class="billOptions" onchange="billingOptions(this)">
<option class="fixedRate">Bill Fixed Rate</option>
<option class="hourly">Bill Hourly</option>
</select>
<input type="text" name="fixedRate" placeholder="Rate" class="fieldWidth100 rate"/>
</tr>
</table>
function billingOptions(){
$(this).closest('.rate').hide();
}
***编辑:此代码不起作用。目标是隐藏 input.rate 元素。