Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery的多级添加更多按钮_Javascript_Php_Jquery - Fatal编程技术网

Javascript 使用jquery的多级添加更多按钮

Javascript 使用jquery的多级添加更多按钮,javascript,php,jquery,Javascript,Php,Jquery,我想使用jquery开发一个多级添加更多按钮 我实现了这个功能,但没有成功。它有很多错误。有一些逻辑问题 我的实际要求是有一个添加更多的按钮。单击此添加更多按钮时,将打开一个Div。在div的一侧有一个文本框和另一个addmore按钮 例如,首先我添加的主选项值是Bajaj。在这个选项下,我想添加一些选项,如Discover,Platina 然后我点击下一步添加更多按钮,并添加下一个选项值是雅马哈在此选项下我需要添加子选项,如FZ,YBR,射线 <div id="tabularoption

我想使用jquery开发一个多级添加更多按钮

我实现了这个功能,但没有成功。它有很多错误。有一些逻辑问题

我的实际要求是有一个添加更多的按钮。单击此添加更多按钮时,将打开一个Div。在div的一侧有一个文本框和另一个addmore按钮

例如,首先我添加的主选项值是Bajaj。在这个选项下,我想添加一些选项,如Discover,Platina

然后我点击下一步添加更多按钮,并添加下一个选项值是雅马哈在此选项下我需要添加子选项,如FZ,YBR,射线

<div id="tabularoptions">
<input id="btnAdd" type="button" value="Add Options" />
<br />
<br />
<div id="TextBoxContainer">
    <!--Textboxes will be added here -->
    <?php
    if ($form['tabularOptions'] != '') {
        foreach ($form['tabularOptions'] as $opt) {
            ?>
            <div  style="border:1px solid #ccc;margin: 10px;">
                <table>
                    <tr>
                        <td>Option Value :</td>
                        <td>
                            <input name = 'tabluarOptionValue_<?php echo $opt['id']; ?>' type="text" value = "<?php echo $opt['tabularOptionValue']; ?>" />
                            <input type="hidden" name="tabluarOptionId_<?php echo $opt['id']; ?>" value="<?php echo $opt['id']; ?>">
                        </td>
                        <td><input type="button" value="Remove" class="remove" /></td>


                        <?php
                        if ($form['tabularSubOptions'] != '') {
                            foreach ($form['tabularSubOptions'] as $optsub) {
                                if ($optsub['tabularOptionId'] == $opt['id']) {
                                    ?>
                                <tr>
                                    <td>
                                        <input type="text" name="tabularSuboptionValue_<?php echo $optsub['id']; ?>" value="<?php echo $optsub['tabularSuboptionValue']; ?>">
                                        <input type="hidden" name="tabularSuboptionId_<?php echo $optsub['id']; ?>" value="<?php echo $optsub['id']; ?>">
                                        <input type="button" class="subOptionRemove" value="X">
                                    </td>
                                </tr>

                                <?php
                            }
                        }
                    }
                    ?> 
                    </tr>
                    <tr>
                    </tr>
                    <tr>
                    <table>
                        <tr class="subOptionDiv">
                            <td><input class = "btnAdd1" type="button" value = "Add Suboptions" /></td>
                        </tr>
                    </table>
                    </tr>
                </table>
            </div>


<?php
}
} ?>


请尝试此代码可能对您有用

将jquery/javascript代码放在js代码所在的位置

<script type="text/javascript">
$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});
</script>
将这段代码放在php/html文件中您想要的文本框中

<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]"></div>
</div>
试试这个

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">    </script>
<table width="100%" cellpadding="0" cellspacing="0" id="type">
    <tr >
        <td align="left">Subcategory</td>
    </tr>

    <tr>
        <td>Type : <input type="text" name="type" id="type" /></td>
    </tr>

    <tr>
    <td>
    <table width="100%" cellspacing="0" cellpadding="0" > 
        <tr>
        <td>
            <table width="100%" cellspacing="0" cellpadding="0" id="subtype1"> 
                <tr>
                    <td>
                        Subtype : <input type="text" name="type" id="type" />
                    </td>
                </tr>
            </table>
        </td>
        </tr>

        <tr>
            <td>
            <div>
                <input type="button" name="addsub" value="Add Subtype" onclick="addmore('1')" />
            </div>
            </td>
        </tr>
    </table>
    </td>
    </tr>
</table>

<div>      
    <input type="button" name="add" value="Add Type" onclick="addmoretype()" />
</div>
Javascript

num = 2;
function addmore(id)
{
    var tablename = "#subtype"+id;
    $(tablename+' tr:last').after('<tr><td> Subtype: <input type="text" name="type" id="type" />    </td>   </tr>');
}   

function addmoretype()
{
    $('#type tr:last').after('<tr>  <td>Type : <input type="text" name="type" id="type" /></td></tr>    <tr>    <td><table width="100%" cellspacing="0" cellpadding="0" >   <tr>    <td>    <table width="100%" cellspacing="0" cellpadding="0" id="subtype'+ num+'">   <tr>    <td>    Subtype : <input type="text" name="type" id="type" /></td></tr> </table></td>   </tr><tr>   <td>    <div>   <input type="button" name="addsub" value="Add Subtype" onclick="addmore('+ num+')" />   </div>  </td>   </tr></table>   </td></tr>');
    num++;
}           

你有一些代码,对吗?把代码贴出来,让你更理智一些,朋友,我是在科哈纳开发的。。。我将发布该代码。据我所知,这不是@Franklin所期望的行为。该代码在逻辑上是错误的。因为您使用的是num++,所以当我们选择编辑选项时,它将不适用于多级。下一件事是我需要添加更多我正在编辑答案。请现在检查。亲爱的谢里什,谢谢你宝贵的支持。你的代码正在运行。我只期待这个。但是我怎样才能得到这个插入值呢。我还需要更新这个。实际上我已经做了这些步骤。。。你可以查我的密码。。。这里我指的是编辑和更新部分。因为在发布后,我们需要确定哪个子选项属于哪个选项。。。。还需要删除选项。。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">    </script>
<table width="100%" cellpadding="0" cellspacing="0" id="type">
    <tr >
        <td align="left">Subcategory</td>
    </tr>

    <tr>
        <td>Type : <input type="text" name="type" id="type" /></td>
    </tr>

    <tr>
    <td>
    <table width="100%" cellspacing="0" cellpadding="0" > 
        <tr>
        <td>
            <table width="100%" cellspacing="0" cellpadding="0" id="subtype1"> 
                <tr>
                    <td>
                        Subtype : <input type="text" name="type" id="type" />
                    </td>
                </tr>
            </table>
        </td>
        </tr>

        <tr>
            <td>
            <div>
                <input type="button" name="addsub" value="Add Subtype" onclick="addmore('1')" />
            </div>
            </td>
        </tr>
    </table>
    </td>
    </tr>
</table>

<div>      
    <input type="button" name="add" value="Add Type" onclick="addmoretype()" />
</div>
num = 2;
function addmore(id)
{
    var tablename = "#subtype"+id;
    $(tablename+' tr:last').after('<tr><td> Subtype: <input type="text" name="type" id="type" />    </td>   </tr>');
}   

function addmoretype()
{
    $('#type tr:last').after('<tr>  <td>Type : <input type="text" name="type" id="type" /></td></tr>    <tr>    <td><table width="100%" cellspacing="0" cellpadding="0" >   <tr>    <td>    <table width="100%" cellspacing="0" cellpadding="0" id="subtype'+ num+'">   <tr>    <td>    Subtype : <input type="text" name="type" id="type" /></td></tr> </table></td>   </tr><tr>   <td>    <div>   <input type="button" name="addsub" value="Add Subtype" onclick="addmore('+ num+')" />   </div>  </td>   </tr></table>   </td></tr>');
    num++;
}