Javascript operations on html control instances (adding html to javascript) _ basic knowledge

Source: Internet
Author: User
Almost all HTML tags can be called HTML controls, such as select, input, div, and table. Html Tag operations are very popular. How to use javascript to operate HTML controls is described below: The Code is as follows:


// Fill in the drop-down list

_ ShowSchools: function (data) {// data indicates a data Object

Var mySelect = document. getElementById ("selectSchools"); // obtain the drop-down list
MySelect. options. length = 0;
// Add option to the select label
For (var index in data ){
Var item = data [index];
Var opp = new Option (item. SchoolName, item. name); // The first parameter indicates the content displayed in the drop-down box, and the second parameter indicates the content selected in the drop-down box.
Opp. name = "option" + index;
MySelect. add (opp );
}
},

// Retrieve the content from the drop-down list
Var schoolId = document. getElementById ("selectSchools"). value;

// We usually select the selected content in the drop-down box instead of the displayed content. How can we get the displayed content? The following shows how to get the selected content in the drop-down box.
Function on_idmbzd_change (){
Var sel_obj = document. getElementById ("idMbzd ");
Var index = sel_obj.selectedIndex;
Alert (sel_obj.options [index]. value );
Alert (sel_obj.options [index]. text );
}

// Obtain the content of the single-choice button
Var chkObjs = document. getElementsByName ("radio ");
Var checkvalue = null;
For (var I = 0; I <chkObjs. length; I ++ ){
If (chkObjs [I]. checked ){
Checkvalue = parseInt (chkObjs [I]. value );
}
}

// Set the radio button
If (entity. SelectType = 1) document. getElementById ("SelectType"). checked = true;
If (entity. SelectType = 0) document. getElementById ("UnSelectType"). checked = true;

// Set the multiple choice box
SetCheckBox: function (data ){
Var courseList = document. getElementsByName ("CourseList ");
For (var I = 0; I <courseList. length-1; I ++ ){
If (courseList [I]. value = data ){
CourseList [I]. checked = true;
}
}

},

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.