0
我有以下的HTML標記。在dropdown
更改select element (project_dp)
,那麼我提取父div
。並獲得parent div
後,我提取parent div
的next div
。之後,當我嘗試使用find
方法獲得select element(task)
存在於這個div內,那麼我什麼都沒有。無法找到div中使用jquery的select元素?
<div class="div_cell">
<select class="form-control project_dp" id="log_time_project_id" name="log_time[project_id]" onchange="populate_tasks($(this))">
<option value=""></option>
<option disabled="true" selected="selected">Please Select</option>
<option value="18">akjsda</option>
<option value="19">approval process and approvers save test</option>
<option value="39">billable test</option></select>
</div>
<div class="div_cell">
<select class="form-control task" id="log_time_task_id" name="log_time[task_id]"></select>
</div>
和jQuery的邏輯
function populate_tasks(project_dp) {
div_node = project_dp.parent();
next_div = project_dp.parent().next("div").find("select.task");
alert(next_div.html()); // giving nothing.
}
,但我無法得到element(select.task)
存在於next_div
。當我用alert
聲明看html
時,那麼它什麼都沒有返回。
好的,我想要去獲得這個元素,我想用一些選項填充這個空的下拉菜單。我如何使用jQuery來做到這一點?我想要的一些示例代碼。 – John
@John,更新了答案 – Satpal