duankui1532 2015-04-19 21:20
浏览 30

如何在克隆的选择菜单列表中选择值 - JQuery Mobile

I'm using "Add/remove fields dynamically" script Based on the great post by Charlie Griefe. However when I try to clone a select menu jQuery Mobile only allows me to select the value in the static select menu.

The Script to clone my select menu

<script>


$(document).ready(function() {


    $('#btnAdd').click( function() {

        $('#btnDel').removeAttr('disabled').button('enable'); // enable the "del" button

        // how many "duplicatable" input fields we currently have
        var num = $('.clonedInput').length; 

        // the numeric ID of the new input field being added  
        var newNum  = new Number(num + 1);    
        var newElem = $('#input' + num ).clone().attr('id', 'input' + newNum);

        newElem.children(':first').attr( 'id', 'name' + newNum ).attr('name', 'name_label[]');
        $('#input' + num).after(newElem);


        // business rule: limit the number of fields to 5
        if (newNum == 5) {
             $('#btnAdd' ).attr('disabled', 'disabled').button('disable');
             $('#btnAdd').parent().find('.ui-btn-text').text('maximum fields reached');
        }                        
    });

    $( '#btnDel' ).click( function() {
        // how many "duplicatable" input fields we currently have           
        var num = $( '.clonedInput' ).length; 

        // remove the last element  
        $('#input' + num ).remove();

        // enable the "add" button, since we've removed one       
        $('#btnAdd').removeAttr('disabled').button('enable'); 
        $('#btnAdd').parent().find('.ui-btn-text').text('add another name');

        // if only one element remains, disable the "remove" button
        if ( num-1 == 1 )
        $('#btnDel' ).attr('disabled', 'disabled').button('disable');

    });  

});           
</script> 

The select menu:

div id="input1" class="clonedInput" style="margin-bottom: 4px;"> 
              <div data-role="fieldcontain">
                   <label for="item_ordered">Ordered Item:</label>
                      <?php
                      $conn = new mysqli('localhost', 'root', 'root', 'retail_management_db') 
                                          or die ('Cannot connect to db');
                    $result = $conn->query("SELECT item_Id,itemName FROM CompanyInventory");

                    echo '<select name="itm_order" value="'.escape(Input::get('itm_order')).'"><option>Select Item</option>';
                         while ($row = $result->fetch_assoc()) {
                            unset($id, $name);
                            $id = $row['item_Id'];
                            $name = $row['itemName']; 
                            echo '<option value="'.$name.'">'.$name.'</option>';
                          }
                    echo '</select>';
                      ?>

                   </div>      
                <div data-role="fieldcontain">

                      <label for="item_ordered">Units:</label>
                        <input type="text" name="quantity" id="quantity" value="<?php  echo escape(Input::get('quantity')); ?>">

                 </div> 
              </div>      
          <div>
              <input id="btnAdd" type="button" value="Add another item" data-inline="true">
              <input id="btnDel" type="button" value="Remove item" disabled="disabled" data-inline="true">
          </div> 

I'm also adding values from my database dynamically into the select menu.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值