我有HTML AJAX形式结构象下面这样:可以nextAll()跳过任何指定的父元素并只查找父级内的子元素吗?
<form name="vafForm" id="vafForm" method="GET" action="urlfor ajax">
<input type="hidden" value="0" id="vafProduct">
<!--<div id="catalog-collection" class="select">-->
<select class="catSelect {prevLevelsIncluding: 'cat'} cat" name="cat" id="catalog" data-level="0">
<option value="0">- Select Cat -</option>
<option value="1">
Federal </option>
<option selected="selected" value="2">
California </option>
</select>
<!--</div>-->
<!--<div id="year-collection" class="select">-->
<select class="yearSelect {prevLevelsIncluding: 'cat,year'} year" name="year" id="year" data-level="1"><option value="0">- Select Year -</option><option value="7">2016</option><option value="3">2012</option></select>
<!--</div>-->
<!--<div id="make-collection" class="select">-->
<select class="makeSelect {prevLevelsIncluding: 'cat,year,make'} make" name="make" id="make" data-level="2"><option value="1">Acura</option></select>
<!--</div>-->
<!--<div id="model-collection" class="select">-->
<select class="modelSelect {prevLevelsIncluding: 'cat,year,make,model'} model" name="model" id="model" data-level="3"><option value="2">Ultra</option></select>
<!--</div>-->
<!--<div id="litre-collection" class="select">-->
<select class="litreSelect {prevLevelsIncluding: 'cat,year,make,model,litre'} litre" name="litre" id="litre"><option value="6">6</option></select>
<!--</div>-->
<div align="center">
<input type="button" style=" padding:5px; margin:5px;" value="Clear" class="vafClear"><input type="button" style=" padding:5px; margin:5px;" class="vafSubmit" value="Submit">
</div>
</form>
这是工作(当选择的第一选择框,那么下一个加载有由AJAX相关数据)如果所有的select
框是彼此相邻,但对于设计问题,我需要在所有选择框周围添加<div>
,并让它们也可以通过ajax下拉选择进行工作。
现在我正在使用jQuery的nextAll
函数,在结构更改时这不是一个好的选择。所以任何人都可以指导我如何在所有选择框周围使用div
?
我目前使用的脚本如下:
if(jQuery('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_startSelect').size()) {
var url = getUrl(jQuery(this).parent('form'), '<?=str_replace(' ','_',$levels[ $i + 1 ])?>');
alert(jQuery('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_startSelect').val());
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_startSelect').html(loadingText);
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_endSelect').html(loadingText);
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_startSelect').load(url, {}, function(responseText) {
jQuery(this).html(responseText);
callbackFunc.apply(this);
});
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>_endSelect').load(url, {}, function(responseText) {
jQuery(this).html(responseText);
callbackFunc.apply(this);
});
} else {
if(jQuery('.<?=str_replace(' ','_',$levels[ $i ])?>Select').val() != "0")
{
var url = getUrl(jQuery(this).parent('form'), '<?=str_replace(' ','_',$levels[ $i + 1 ])?>');
var NewVar = jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>Select').html(loadingText);
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>Select').html(loadingText);
jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>Select').load(url, {}, function(responseText) {
jQuery(this).html(responseText);
callbackFunc.apply(this);
});
}
else
{
//jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>Select').html('<option></option>').attr('disabled','disabled');
//jQuery(this).nextAll('.<?=str_replace(' ','_',$levels[ $i + 1 ])?>Select').prop('disabled', true);
jQuery(this).nextAll('select').each(function() {
//jQuery(this).html('<option></option>').prop('disabled',true);
jQuery(this).prop('disabled',true);
});
}
}
我没有太大的脚本家伙。
在js所有的PHP?你真的需要这样做吗? – 2016-01-21 06:10:47
这是一个预建模块,这是我在许多网站使用的模块的默认代码,但只是为了这个网站,我需要在选择框中添加div。我正在寻找的是'nextAll'替代方法,即使它们被各自的div标签包围,也可以获得所有选择框 –
为什么你的类以这种方式命名 - yearSelect {prevLevelsIncluding:'cat,year'} year'? –