我創建了一個名爲billingOptions()的函數,它與下拉(select)元素相關聯。當用戶在下拉菜單中選擇一個選項時,該功能就會運行。Jquery onChange運行此功能
下拉將動態地通過頁面添加...每次添加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元素。
這看起來很好,你面臨什麼問題? – Mrchief
這樣做的效果是否正確? http://jsfiddle.net/vzfyz/ –
沒有任何反應。我編輯了代碼以顯示.rate類的輸入。 –