How to select ____js through JS dynamic Setup Select option

Source: Internet
Author: User

Today, the development of the Web site encountered a small problem, how to dynamically through JS to select the selected control check the specified value. During debugging, the problem of Amazeui this UI component was discovered, and the style of its components could not be set to be selected by Selected=true.

Later, went to the official website to find the relevant methods to achieve, but in accordance with the official website of the code can not reach the selected effect, and finally can only remove the style, using the original HTML style, manually through JS to achieve this function.

Solutions

Manually through the native JS to achieve:

/** 
 * Set the Select control 
 to select the ID value of the * @param selectid SELECT * 
 @param checkvalue Select the value of option 
 * @author standard brother  
* * function set_select_checked (Selectid, CheckValue) {  
    var select = document.getElementById (Selectid);  

    for (var i = 0; i < select.options.length i++) {  
        if (Select.options[i].value = = CheckValue) {  
            select.options[i ].selected = true;  
            break;  
        }}}  

And then call it by:

Set Select to select the team
set_select_checked (' Edit-group ', group_id);

Note: Do not pass ' #edit-group ', accustomed to jquery, there will be problems ~

The problem is simple, but write it down and copy it directly next time.

Article Source: http://tech.yunyingxbs.com/article/detail/id/343.html

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.