Home > Web Front-end > JS Tutorial > body text

js select option object summary_javascript skills

WBOY
Release: 2016-05-16 17:08:11
Original
1187 people have browsed it

Basic understanding:

var e = document.getElementById("selectId");

e. options= new Option("text","value");

//Create an option object, that is, create one or more

in the





< input type="button" name="button" value="View results" onclick="number();">



Based on these things, I implemented a small function using JQEURY AJAX JSON as follows:

JS code: (only the code related to SELECT is taken)

Copy code The code is as follows:

/**
* @description Component linkage drop-down list (implemented using JQUERY's AJAX and JSON)
* @prarm selectId The ID of the drop-down list
* @prarm method The name of the method to be called
* @prarm temp this Store the software ID
* @prarm url The address to jump to
*/
function linkAgeJson(selectId,method,temp,url){
$j.ajax({
type: "get",//Use The get method accesses the backend
dataType: "json",//returns data in json format
url: url,//the backend address to be accessed
data: "method=" method "&temp=" temp, //Data to be sent
Success: function(msg){//msg is the returned data, data binding is done here
var data = msg.lists;
coverJsonToHtml(selectId,data);
                                                                                                                                                 
/**
* @description Convert JSON data into HTML data format * @prarm selectId The ID of the drop-down list

* @prarm nodeArray The returned JSON array
*
*/
function coverJsonToHtml(selectId,nodeArray){
//get select
var tempSelect=$j("#" selectId);
//clear select value
isClearSelect(selectId,'0');
var tempOption=null;
for(var i=0;i//create select Option
tempOption= $j(' ');
//put Option to select
tempSelect.append(tempOption);
}
                                                                                                                   
function isClearSelect(selectId,index){
var length=document.getElementById(selectId).options.length;
while(length!=index){
//The length is changing, Because it must be reacquired
         length=document.getElementById(selectId).options.length; i);
length=length/2;
}
}

/**
* @description Clear the value of the drop-down list
* @prarm selectId The ID of the drop-down list
* @prarm index The subscript position to start clearing
*/
function getCpgjThgl(selectId1,selectId2){
var obj1 =document.getElementById(selectId1);//Reference software drop-down list
var obj2=document.getElementById(selectId2);//Degenerate component drop-down list
var len=obj1.options.length;
// Return when the length of the referenced software list is equal to 1, no operation is performed
if(len==1){
          return false;
  }
  //Clear the value of the drop-down list, both methods are available
// isClearSelect(selectId2,'1');
document.getElementById(selectId2).length=1;
for(var i=0;ivar option = obj1.options[i];
//The selected items of the referenced software are not added
if(i!=obj1.selectedIndex){
//Clone OPTION and add it to SELECT
obj2. appendChild(option.cloneNode(true));
}
}

}


HTML code:




Copy code

The code is as follows:



 
  *引用软件:



onClick="linkAgeTree('linkage','yyrjtree','yyrjMc','yyrjDm','linkageTree','1');" value="选择...">

 

 


 

 

 


  

 

*引用分版:
退化构件:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!