开发者

Javascript/jquery : retain option item of select box

I have select box

<select id="abc">
<option value="1">xyz</option>
<option value="2">pqr</option>
</select>

Through third party javascript, it is removing all options

document.getElementById("abc").options.length=1; // third party code

Now how do i retain those options again ,as i can see them in the browser page source. How to do this through javascri开发者_C百科pt/jquery? is this possible? can someone help.

Thanks


You could store a clone of those options. With this:

window.$clonedOptions = $("#abc option").clone(); //Saves option clones

Then, to restore them, you can do:

$("#abc").empty().append(window.$clonedOptions);

Hope this helps. Cheers


What you see in the browser view source is the one that is generated at the time of page load and not the one that is generated dynamic (by javascript).

Please inspect the select box using FireBug and check whether there are options or not.

If you don't have any options then you won't be able to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜