select2 ajax方式怎么添加空的option,可以选择空的option实现清空功能,现在我只能通过清除按钮实现清空

select2 ajax方式怎么添加空的option,可以选择空的option实现清空功能,现在我只能通过清除按钮实现清空,第1张

清空option 不是很难的 *** 作。只需要遍历现有option,将其每个子元素都置空即可。

代码如下:

function clearOption(selectId){

var selectObj = document.getElementById(selectId)

for(var i = 0,len = selectObj.options.lengthi <leni++){

selectObj.options[0] = null

}

}

你这样好了,执行一次ajax,在成功返回的函数里面再进行ajax请求~

var a = new Array(1,2,3)

var i=0

Loop_ajax(a[i],i,a)

function Loop_ajax(value,identity,array){

$.getJSON( "url?value="+ value , null , function(){

if(identity<array.length){

Loop_ajax(array[identity+1],identity+1,array)

}

else{

alert('循环玩啦')

return false

}

})

}

---------------------------------

对于2楼的答案~

$.ajax有这个option

sucess: callback

这里就可以定义成功时的返回值。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11642625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存