2014-03-12 120 views
0

這個問題是另一個問題我也問過早期URL將文本輸入值到其他空文本字段 - jQuery的

我生成動態行繼續和所有的領域正在使用JS因此輸入填充所有文本框的ID都不相同。現在,如果用戶在「全部應用」輸入欄中輸入一個數字,並單擊該按鈕,則應在所有添加在該投影片上的行中設置相同的數字。

HTML結構,其中我動態添加行

<div id="bets"> 
    <div id="idNo1" class="bet gray2" name="singleBet"> 
    <div class="left"> 
     <p class="title"> 
     <p class="supermid"> 
      <input id="input_1" type="text"> 
    </div> 
    </div> 
    <div id="idNo2" class="bet gray2" name="singleBet"> 
    <div class="left"> 
     <p class="title"> 
     <p class="supermid"> 
      <input id="input_2" type="text"> 
    </div> 
    </div> 
    <div id="idNo3" class="bet gray2" name="singleBet"> 
    <div class="left"> 
     <p class="title"> 
     <p class="supermid"> 
      <input id="input_3" type="text"> 
    </div> 
    </div> 
</div> 

JS用於applyToall功能

在個體投注applyTOall按鈕加法元件

BetSlip.prototype.createSingleBetDiv = function(Bet) { 

    var id = Bet.betType + '_' + Bet.productId + '_' + Bet.mpid, 
     divId = id + '_div'; 

    // If such bet already exists 
    if (typeof document.betSlip.singleDivs[divId] == "undefined") { 
     var div = element.create('div'), 
      a = element.create('a'), 
      leftDiv = element.create('div'), 
      closeDiv = element.create('div'), 
      singleBetNumber = ++document.getElementsByName('singleBet').length; 

     element.setId(div, divId); 
     element.setName(div, 'singleBet'); 
     element.setClassName(div, 'bet gray2'); 
     element.setClassName(a, 'right orange'); 
     element.setClassName(leftDiv, 'left'); 
     element.setClassName(closeDiv, 'icon_shut_bet'); 

     // Info abt the bet 
     $(leftDiv).append('<p class="title"><b><span class="bet_no">' + singleBetNumber + '</span>.&nbsp;' + Bet['horseName'] + '</b></p>'); 
     var raceInfo = ""; 
     $("#raceInfo").contents().filter(function() { 
      if (this.nodeType === 3) raceInfo = $(this).text() + ',&nbsp;' + Bet['betTypeName'] + ' (' + Bet['value'].toFixed(2) + ')'; 
     }); 
     $(leftDiv).append('<p class="title">' + raceInfo + '</p>'); 

     // Closing btn 
     (function(id) { 
      a.onclick=function() {document.betSlip.removeSingleBet(divId);}; 
     })(id); 
     $(a).append(closeDiv); 

     // Creating input field 
     $(leftDiv).append('<p class="supermid"><input id="' + id + '_input\" type="text"></p>'); 

     // Creating WIN/PLACE checkbox selection 
     $(leftDiv).append('<p><input id="' + id + '_checkbox\" type="checkbox"><b>' + winPlace + '</b></p>'); 

     // Append left part 
     $(div).append(leftDiv); 
     // Append right part 
     $(div).append(a); 
     // Appending div with data 
     $.data(div, 'Bet', Bet); 

     // Add div to the bet slip map 
     document.betSlip.singleDivs[divId] = div; 

     return div; 
    } 
    else { 
     $("#betSlipError").show(); 
     $("#betSlipError").html(sameBet); 
     return null; 
    } 
} 

HTML

<a onclick="document.betSlip.applyToAll(event)" class="button apply orange">APPLY TO ALL <input type="text"> </a> 

JS

BetSlip.prototype.applyToAll = function(e) { 
    e.preventDefault(); 
    document.betSlip.applyToAllBetInput($(this).find("input").val()); 
} 

BetSlip.prototype.applyToAllBetInput = function(value) { 
    $("#bets div[name=singleBet] .supermid input:text").val(value); 
} 
+0

@Archer這裏是我用前一個問題代替的新問題。 – zaq

+0

請創建小提琴嗎? – halkujabra

+0

@ user1708762我已添加鏈接到現場網站。 – zaq

回答

1

嘗試這樣做是這樣的:

$('yourbutton').on('click', function(){ 
    var applyVal = $('applyvalinput').val(); 
    $('#bets').find('[id^="input"][type="text"]').val(applyVal); 
});//^------finds the inputs in this specific div. 

點擊您的按鈕,並緩存你的值適用於所有輸入VAL並檢查它具有IDS通過啓動[id^="input"]輸入術語輸入並將其應用於每個文本輸入。

相關問題