Js provides two methods for getting the value of the drop-down box and text on the Internet: But some people are very irresponsible, and they do not consider the errors caused by the differences between browsers, which leads many novices to figure out the errors after thinking for a long time!
Below I will summarize the values and text of the selected items in Firefox and IE to get the drop-down box:
1. Methods supported by both IE and Firefox:
Get text
The code copy is as follows:
var obj=document.getElementById('select_template');
var text=obj.options[obj.selectedIndex].text;//Get text
var obj=document.getElementById("select_template");
for(i=0;i<obj.length;i++) {//The length of the drop-down box is its number of options
if(obj[i].selected==true) {
var text=obj[i].text;//Get text
}
}
The previous method is simpler
2. IE supports Firefox and does not support:
The code copy is as follows:
var obj=document.getElementById(name);
for(i=0;i<obj.length;i++) {
if(obj[i].selected==true) {
var text= obj[i].innerText;
}
}
Get value methods IE and Firefox are common:
var value=document.getElementById("select_template").value;//Get the value
Summary: In fact, it is mainly that both IE and Firefox support value and text attributes, and Firefox does not support innerText attributes.
Js implements the current page to open a new link:
window.location.href=url;