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>. ' + Bet['horseName'] + '</b></p>');
var raceInfo = "";
$("#raceInfo").contents().filter(function() {
if (this.nodeType === 3) raceInfo = $(this).text() + ', ' + 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);
}
@Archer這裏是我用前一個問題代替的新問題。 – zaq
請創建小提琴嗎? – halkujabra
@ user1708762我已添加鏈接到現場網站。 – zaq