最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to remove selection from a listbox in html by javascript and jQuery? - Stack Overflow

programmeradmin0浏览0评论

After I click an item on a listbox, I'll do this processing then I need to remove this selection as it was at the first time so that I can click the same item again and fire the event of selected index change.

After I click an item on a listbox, I'll do this processing then I need to remove this selection as it was at the first time so that I can click the same item again and fire the event of selected index change.

Share Improve this question asked Feb 9, 2011 at 14:20 Ahmad FaridAhmad Farid 14.8k45 gold badges98 silver badges138 bronze badges 1
  • do you need any more help with this question? :-) – Andy E Commented Feb 15, 2011 at 9:57
Add a ment  | 

1 Answer 1

Reset to default 8

Set the selectedIndex property to -1:

// Plain JS:
document.getElementById("myList").selectedIndex = -1;

// Using jQuery to select the element:
$("#myList")[0].selectedIndex = -1;

Working demo: http://jsfiddle/n84AW/

发布评论

评论列表(0)

  1. 暂无评论