【发布时间】:2012-10-16 12:26:36
【问题描述】:
我正在使用 n 级选择链 99 points website tutorial, 但是当我尝试重新选择父节点时,相应的子 div 不会被重置。
我已经在 StackOverflow 和 Google 上进行了搜索,但到目前为止没有运气。
以下代码出错,我无法更正。
$(this).nextAll('.parent').remove();
$(this).nextAll('label').remove();
这是我的代码
主页
<script type="text/javascript">
$('.parent').livequery('change', function() {
$(this).nextAll('.parent').remove();
$(this).nextAll('label').remove();
$.post("/dashboard/details/show_levels/", {
parent_id: $(this).val(),
}, function(response){
setTimeout("finishAjax('levels', '"+escape(response)+"')", 400);
});
return false;
});
})
function finishAjax(id, response){
//alert(unescape(response));
$('#'+id).append(unescape(response));
}
</script>
<div id=levels>
<select id="level" class="parent" multiple="multiple" scroabble="1" name="data[level][]">
<option value="Building & Construction Mat">Building & Construction Mat</option>
<option value="Electronic Components">Electronic Components</option>
<option value="Furniture & Mattresses">Furniture & Mattresses</option>
<option value="Labels">Labels</option>
</select>
</div>
show_levels
<select id="sublevel" class="parent" multiple="multiple" scroabble="1" name="data[sublevel][]">
<option value="Labels">Labels</option>
<option value="Preparation Techniques">Preparation Techniques</option>
<option value="Process Parameters">Process Parameters</option>
</select>
更新
以下代码解决了我的问题
$("#levels").on('click', '.parent', function () {
$(this).parents().nextUntil().remove();
});
【问题讨论】:
-
请在此处发布您的代码,以便我们无需访问外部站点即可进行调试。
-
实时源 html 会有所帮助,而不是您的 php 表单帮助程序代码。由于您正在使用遍历,因此层次结构很重要
-
您使用的是演示中提供的
.livequery(),我认为它已经过时了,因为它使用的是 jquery 1.3.2。你应该使用.on()(当然这不会解决你的问题) -
@CrisimIlNumenoreano 我正在使用带有 jquery 1.8.2 的 livequery,因为应用程序上还有其他功能依赖于它并且与 jquery 1.3 不兼容那么你有什么建议?
-
@charlietfl live html 代码更新
标签: php javascript jquery livequery