开发者

Getting text of html select in javascript?

开发者 https://www.devze.com 2022-12-27 04:38 出处:网络
select.onchange = function() { this.value; } It\'s easy to retrieve the value b开发者_高级运维ut now I need the text of the selected element. How to do it? (Sorry... put .value before my edit inst
select.onchange = function() {
   this.value; 

}

It's easy to retrieve the value b开发者_高级运维ut now I need the text of the selected element. How to do it?


(Sorry... put .value before my edit instead of .text by accident 8-)...)

this.options[this.selectedIndex].text


//assuming "this" is the select element
if (this.selectedIndex >= 0) {
  this.options[this.selectedIndex].text = "some text";
}
0

精彩评论

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