HTML and instructions for the definition and use of labels
The element is used to create a pull-down list.
The label in the element defines the options available in the list.
Tips and comments
Tip: The element is a form control that can be used to accept user input in a form.
The difference between HTML 4.01 and HTML5
HTML5 adds some new properties.
Create a selection list with 4 options:
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Try it out . . .
Browser support
All major browsers support the label.
Property
New : The new property in HTML5.
Attributes | value | describe |
---|---|---|
autofocus New | autofocus | It is specified that the drop-down list is automatically obtained when the page is loaded. |
disabled | disabled | When this property is TRUE, the drop-down list is disabled. |
form New | form_id | Define one or more forms belonging to the Select field. |
multiple | multiple | When this property is TRUE, multiple options can be selected. |
name | name | Define the name of the drop-down list. |
required New | required | Specifies that the user must select an option in a drop-down list before submitting the form. |
size | number | Specify the number of visible options in the drop-down list. |
Global properties
The label supports the global properties of HTML.
The event property
The tag supports the event properties of HTML.
Related articles
HTML DOM Reference Manual: Select Object
Summary of tips for using the label
1. Dynamic creation of select
function createSelect(){
var mySelect = document.createElement("select");
mySelect.id = "mySelect";
document.body.appendChild(mySelect);
}
2. Add option options
function addOption(){
Find objects based on id,
var obj=document.getElementById('mySelect');
Add an option
obj.add (new Option ("text," "value");
}
3. Remove all options options
function removeAll(){
var obj=document.getElementById('mySelect');
obj.options.length=0;
}
4. Remove an option option
function removeOne(){
var obj=document.getElementById('mySelect');
index, to remove the serial number of the option, take the serial number of the currently selected option here
var index=obj.selectedIndex;
obj.options.remove(index);
}
5. Get the value of the option option
var obj=document.getElementById('mySelect');
var index=obj.selectedIndex; Ordinal number, taking the serial number of the currently selected option
var val = obj.options[index].value;
6. Get the text of the option option
var obj=document.getElementById('mySelect');
var index=obj.selectedIndex; Ordinal number, taking the serial number of the currently selected option
var val = obj.options[index].text;
7. Modify the option option option option
var obj=document.getElementById('mySelect');
var index=obj.selectedIndex; Ordinal number, taking the serial number of the currently selected option
var val s obj.options s index s new Option ("new text", "new value");
8. Delete the select
function removeSelect(){
var mySelect = document.getElementById("mySelect");
mySelect.parentNode.removeChild(mySelect);
}
9. Set select option is selected
function removeSelect(){
Dynamically add employees to the operator's pull-down list
for ( var i = 0; i < json.length; i++) {
var newOption = new Option(json[i].empname, json[i].empid, i);
Add employee information to the operator's pull-down list
objDeal.options.add(newOption);
The customer salesman's ID is not empty
if(empbyDealEmpId!="" || empbyDealEmpId!=0){
If the employee id is equal to the value in the drop-down list, the drop-down list is selected
if(empbyDealEmpId==objDeal.options[i].value){
Determine that this pull-down list is selected
objDeal.options[i].selected=true;
}
}
}
}
Case:
How do I make select in html unselectable?
<form id="form1" name="form1" method="post" action="">
<select name="select">
<option>aa</option>
<option disabled="disabled">bb</option>
<option>cc</option>
</select>
</form>
How do I adjust the width of the select?
<style>.s1{ width: 200px;}</style>
<select class="s1">
<OPTION>很长很长也能显示</OPTION>
<OPTION>很长很长也能显示</OPTION>
</select>
html select tag plus link 3 methods
html select tag plus link methods have many, next for you to introduce the next few more classic, interested friends can refer to, hope to help you.<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>select加链接</title>
</head>
<body>
<SCRIPT language=javascript>
<!--
// open the related site windows
function mbar(sobj) {
var docurl =sobj.options[sobj.selectedIndex].value;
if (docurl != "") {
open(docurl,'_blank');
sobj.selectedIndex=0;
sobj.blur();
}
}
//-->
</SCRIPT>
<Select onchange=mbar(this) name="select">
<OPTION selected>=== 合作伙伴 ===</OPTION>
<OPTION value="http://www.baidu.com">百度</OPTION>
<OPTION value="http://www.w3cschool.cn">w3cschool在线教程</OPTION>
<OPTION value="http://www.w3cschool.cn">优聚</OPTION>
</Select>
</body>
</html>
<select name="pageselect" onchange="self.location.href=options[selectedIndex].value" >
<OPTION value="http://www.baidu.com">百度</OPTION>
<OPTION value="http://www.w3cschool.cn">w3cschool在线教程</OPTION>
</select>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>select选择-按钮跳转</title>
<script type="text/javascript">
function setsubmit()
{
if(mylink.value == 0)
window.location='http://www.baidu.com';
if(mylink.value == 1)
window.location='http://www.w3cschool.cn';
if(mylink.value == 2)
window.location='http://www.w3cschool.cn';
}
</script>
</head>
<body>
<select name="mylink" id="mylink">
<OPTION value="0">百度</OPTION>
<OPTION value="1">w3cschool在线教程</OPTION>
<OPTION value="2">优聚</OPTION>
</select>
<input type="button" id="btn" value="提交" onclick="setsubmit(this)" />
</body>
</html>
Expand your knowledge
SELECT can also be used as SQL ( Structured query language The query statement is used, SELECT statement Returns the result of the query in a database with the specified criteria, the result returned as a collection of records. For more information about SQL, you can refer to the full SQL Tutorial on this site!