在优化以下jquery代码时需要帮助 [英] Need help in Optimizing the below jquery code
本文介绍了在优化以下jquery代码时需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以优化下面的代码行?
Is there any way to Optimize the below lines of code?
$('#state').children('option:not(:first)').remove();
$('#city').children('option:not(:first)').remove();
$('#branch').children('option:not(:first)').remove();
$('#branchAddress').children('option:not(:first)').remove();
我尝试用逗号分隔添加所有字段,但是它不起作用.
I have tried adding all the fields by comma seperated, but it is not working.
请帮助优化上述代码.
推荐答案
我会尝试以下方法:
$('#state, #city, #branch, #branchAddress')
.each(function(i,item){$('option:not(:first)',$(item)).remove();});
或这样:
$('#state, #city, #branch, #branchAddress').find('option:not(:first)').remove();
最后(但我不会称其为优化;-)
at last (but I wouldn't call it optimization ;-)
$('#state option:not(:first), #city option:not(:first), #branch option:not(:first), #branchAddress option:not(:first)').remove();
这篇关于在优化以下jquery代码时需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文