JQuery: Dynamically create select Tag

后端 未结 4 573
一个人的身影
一个人的身影 2020-12-16 12:40

I am using JQuery to dynamically (based on user choice) create tag. User enters require options in a text box and my code creates select tag of it. Script is:



        
4条回答
  •  别那么骄傲
    2020-12-16 13:19

    
    /* 1- First get total numbers of SELECT tags used in your page to avoid elements name/id issues.
     * 2- Get all OPTIONS user entered with comma separator into a text box.
     * 3- Split user OPTIONS and make an array of these OPTIONS.
     * 4- Create SELECT code.
     * 5- Appent it into the temp div (a hidden div in your page).
     * 6- Then get that code.
     * 7- Now append code to your actual div.
     * 8- Filnally make empty the temp div therfore it will be like a new container for next SELECT tag.
     */
    
    total = $("select").size() + 1;                                         // 1-
    var myoptions = $("#myoptions").val();                                  // 2-
    var data = myoptions.split(',');                                        // 3-
    var s = $("
                            
        
    提交评论

提交回复
热议问题