How to achieve radio and multi-selection in HTML

This article mainly introduces how the SELECT tag in HTML achieves radio and multi-selection, has a certain reference value, and friends needed can be referred to. I hope that everyone has a big gain after reading this article. Let’s take a look at you with everyone.

SELECT element can create a radio or multi-selected menu. When submitting a form, the browser will submit the selected item, or collect multiple options separated by commas, synthesize a separate parameter list, including the Name property when the form data is submitted to the server.

First, the basic usage:

    Volvo   Saab   Opel      wherein the 
tag can be saved, in the page


 Hubei Electric Network Learning Center  Chengdu Normal University Network Learning Center  Wuhan Vocational and Technical College Network Learning Center      Second, the SELECT element can also be selected, see the following code:  
// There is a multiple attribute, you can choose

high school

University
 // There is no multiple attribute below, only one, can not be selected   High school   University   Ph.D.  // The following is a case where the size property is set. If SIZE = 3 is displayed, three data is displayed, and attention cannot be selected.  Primary school   Junior high school   High school    Undergraduate   Postgraduate   Doctoral   Postdes   Please select     Third, all common operations involved in the select component:   1. Determine if there is an item of the specified value in the SELECT option      id @param objItemValue @param objSelectId be verified to be the target select component verification value function isSelectItemExit (objSelectId, objItemValue) whether there is a {var objSelect = document.getElementById (objSelectId) VAR ISEXIT = false; if (null! = Objselect && typeof (objselect)! = "undefined") {for (var i = 0; i      2. Add an item  


@Param ObjselectID to join the Item’s target Select component ID @Param ObjitemText will join the item displayed @Param ObjitemValue will join Item Value Function AddoneItemTOSELECT (ObjSelectid, ObjitemText, Objitemvalue) {var objselect = document.getlementbyid (ObjSelectID); if (NULL! = Objselect && typeof (objselect)! = “undefined”) {// Judgment whether the value of this value is already in Select (isselectItemValue) {$ .MESSAGER.Alert (‘prompt Message ‘,’ The value of this value already exists! ‘,’ Info ‘);} else {var valuem = new option (ObjitemText, objitemvalue; objselect.Options.add (varItem);}}}

3. From the Select option to delete the selected item, support multiple choices
  <objSelect.options.length;i++) { 
if(objSelect.options[i].value == objItemValue) { 
isExit = true; 
break; 
} 
} 
} 
return isExit; 
} 
@Param ObjselectID will be deleted SELECT Component ID Function RemoveselectItemsFromSelect (objSelectID) {var objselect = document.getlementByid (objSelectID); var delnum = 0; if (null! = objselect && typeof (objselect)! = “undefined”) {for (var i = 0; i



4. Delete an item

   @Param ObjSelectID to verify the id @Param Objitemvalue of the target Select component Verify that the value exists Function RemoveItemFromSelectByItemValue (Objselectid, objItemValue) {var objSelect = document.getElementById (objSelectId);! if (null = objSelect && typeof (objSelect)! = "undefined") {// determines whether there if (isSelectItemExit (objSelect, objItemValue)) {for ( VAR i = 0; i 


5. All options in Select

  <objSelect.options.length;i=i+1) { 
if(objSelect.options[i].selected) { 
objSelect.options.remove(i); 
delNum = delNum + 1; 
i = i - 1; 
} 
} 
if (delNum <= 0 ) { 
$.messager.alert('提示消息','请选择你要删除的选项!','info'); 
} else { 
$.messager.alert('提示消息','成功删除了'+delNum+'个选项!','info'); 
} 
} 
} @Param ObjSelectID will clear the target SELECT Component ID Function Clearselect (ObjselectID) {var objselect = document.getlementByid (objSelectiD); if (null! = Objselect && typeof (objselect)! = "Undefined") {for (var i = 0; i 


6. Get all Item in SELECT, and assemble all values ​​for a string, with a comma with a comma

  [ between the values ​​of all of item 123 @param objSelectId target id @return select the select component], values ​​separated by commas value function getAllItemValuesByString (objSelectId) {var selectItemsValuesStr = ""; var objSelect = document.getElementById (objSelectId); if (NULL! = ObjselECT && TypeOf (Objselect)! = "undefined") {var length = Objselect.Options.Length for (var i = 0; i <objSelect.options.length;i++) { 
if(objSelect.options[i].value == objItemValue) { 
objSelect.options.remove(i); 
break; 
} 
} 
$.messager.alert('提示消息','成功删除!','info'); 
} else { 
$.messager.alert('提示消息','不存在指定值的选项!','info'); 
} 
} 
} 


7. Put a SELECT All selected options are moved to another Select to go

  <objSelect.options.length;) { 
objSelect.options.remove(i); 
} 
} 
} @Param fromobjselectID mobile Item's original SELECT component ID @Param TOOBJECTSELECTID mobile Item will enter the target SELECT component ID function moveAllSelectedToAnotherSelectObject (fromObjSelectId, toObjectSelectId) {var objSelect = document.getElementById (fromObjSelectId); var delNum = 0; if (null = objSelect && typeof (objSelect) = "undefined"!!) {for (var i = 0; i 


8. Move all options in a select to another Select to go to

  @Param fromobjselectID mobile Item Original SELECT Component ID @Param TOOBJECTSELECTID Mobile Item Select Component Id Function MoveAllToanotherselectObject (fromobjselectId) {var objselect = Document.GtelemenTbyid (fromobjselectid); if (null! = objselect) {for (var i = 0; i < length; i = i + 1) { 
if (0 == i) { 
selectItemsValuesStr = objSelect.options[i].value; 
} else { 
selectItemsValuesStr = selectItemsValuesStr + "," + objSelect.options[i].value; 
} 
} 
} 
return selectItemsValuesStr; 
} 

Thank you can read this article carefully, I hope that Xiaobian is shared in HTML How to achieve radio and multi-selection content help everyone, I also hope that everyone will support Tumi Clouds, pay attention to Tumi Cloud Industry Information Channel. If you encounter problems, you will find Tumi clouds, and the detailed solution is waiting for you!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment