Jquery 名称列表选项列表保持乘法 函数addteamSection(){ var teamList=$(“#team_table”); var团队_临时=“”; 变量大小_temp=[“20”、“30”、“40”、“50”、“60”]; 团队列表。追加(“”); 对于(变量s=0;s

Jquery 名称列表选项列表保持乘法 函数addteamSection(){ var teamList=$(“#team_table”); var团队_临时=“”; 变量大小_temp=[“20”、“30”、“40”、“50”、“60”]; 团队列表。追加(“”); 对于(变量s=0;s,jquery,Jquery,我的意图是通过点击按钮创建一个添加名称列表,它将有年龄选择供用户选择,但我的选项保持乘法,因为我有相同的类名,但我假设如何添加以选择不使用任何id,并确保它不是乘法 保持单击几次添加并选中第一个选项,然后重复 像这样分开你的字符串构建 函数addteamSection(){ var teamList=$(“#team_table”); var团队_临时=“”; 变量大小_temp=[“20”、“30”、“40”、“50”、“60”]; var rowString=“” var selectS

我的意图是通过点击按钮创建一个添加名称列表,它将有年龄选择供用户选择,但我的选项保持乘法,因为我有相同的类名,但我假设如何添加以选择不使用任何id,并确保它不是乘法


保持单击几次添加并选中第一个选项,然后重复

像这样分开你的字符串构建

函数addteamSection(){
var teamList=$(“#team_table”);
var团队_临时=“”;
变量大小_temp=[“20”、“30”、“40”、“50”、“60”];
var rowString=“”
var selectString=“”
/*而不是使用var sizeList=$('.sizeList');来选择新的下拉列表
(由于新元素尚未添加到
您可以手动构建选择框,将选项附加到该框中
然后将其附加到DOM元素中*/
对于(变量s=0;s
AdityaParab你在吗?你能帮我再检查一下吗?我试着在里面添加循环号,我试着像你一样断开循环。为什么不工作?我要加1。2.3.
function addteamSection() {
    var teamList = $('#team_table');
    var team_temp = '';
    var size_temp = ["20", "30", "40", "50", "60"];

    teamList.append("<tr><td><input class='name' type='text' name='player_name' /></td><td><input class='number' type='text' name='player_number' /></td><td><select class='sizeList'></select></td></tr>");

    for (var s = 0; s < size_temp.length; s++) {
        var sizeList = $('.sizeList');
        team_temp += "<option value=" + size_temp[s] + ">" + size_temp[s] + "</option>";
    }

    sizeList.append(team_temp);

}
function addteamSection(){
        var teamList = $('#team_table');
        var team_temp = '';
        var size_temp = ["20", "30", "40", "50","60"];

        var rowString = "<tr><td><input class='name' type='text' name='player_name' /></td><td><input class='number' type='text' name='player_number' /></td><td>"
        var selectString = "<select class='sizeList'>"

        /* Instead of using var sizeList = $('.sizeList'); to select the new dropdown
           (which won't work anyway because your new element hasn't been added to the 
           DOM yet.) You can manually build the select box, append the options to it
           and then append it to your DOM element.*/

        for(var s = 0; s < size_temp.length; s++){

            selectString += "<option value="+size_temp[s]+">"+size_temp[s]+"</option>";
        }

    selectString+="</select></td></tr>";
    rowString+=selectString;
    teamList.append(rowString);


    }
addteamSection();

$('#addf').click(function() {
    addteamSection();
});