Home >Web Front-end >JS Tutorial >Js implementation code to obtain the value and text of the selected item in the drop-down box_javascript skills
Js provides two methods to obtain the value and text of the drop-down box: But some people are very irresponsible. They do not consider the errors caused by the differences between browsers, causing many novices to figure it out for a long time and cannot find it. mistake!
Below I summarize how to get the value and text of the selected item in the drop-down box under Firefox and IE:
1. Methods supported by both IE and Firefox:
Get text
var obj=document.getElementById("select_template");
for(i=0;i
var text=obj[i].text;//Get text
}
}
for(i=0;i
var text= obj[i].innerText;
}
}
Summary: In fact, the main reason is that both IE and Firefox support the value and text attributes, but Firefox does not support the innerText attribute.
Js implements opening a new link on the current page:
window.location.href=url;