希望你能帮助我,我认为你真的很容易解决:)。为每一行重复代码jquery
我有以下的jQuery脚本:
$('#addpricebtn').click(function() {
$('.stidinput').each(function (i) {
$.ajax({
type: 'GET',
url: '/Builder/rateretriever',
datatype: 'json',
data: { id: $('.stidinput').val() },
success: function (result) {
$('.categoryinput').html(result[i].category + ' - ' + result[i].subcategory + ' - ' + result[i].site);
$('.formatinput').html(result[i].format);
$('.exclusiveinput').html(result[i].exclusive);
$('.cminput').html(result[i].costmethod);
}
});
});
});
这个脚本工作,但只着眼于首先填写ID,我想使用的代码的每一行,这就是为什么我有下面的代码...(我想用不同的ID使用相同的请求对每一个是越来越被用户:)填充线)
$('#addpricebtn').click(function() {
$('.stidinput').each(function (i) {
var inputer = $('.stidinput').val();
$.ajax({
type: 'GET',
url: '/Builder/rateretriever',
datatype: 'json',
data: { id: inputer[i] },
success: function (result) {
$('.categoryinput').html(result[i].category + ' - ' + result[i].subcategory + ' - ' + result[i].site);
$('.formatinput').html(result[i].format);
$('.exclusiveinput').html(result[i].exclusive);
$('.cminput').html(result[i].costmethod);
}
});
});
});
希望你能帮助:)。
编辑
当然,我有以下的HTML代码:
<div class="io-container">
<table id="iolist">
<tr>
<th>ID</th>
<th>Name:</th>
<th>Format:</th>
<th>Exclusive:</th>
<th>Start:</th>
<th>End:</th>
<th>Cost Method:</th>
<th>Target 1:</th>
<th>Target 2:</th>
<th>Frequency Cap:</th>
<th>RC Price:</th>
<th>Impressions:</th>
<th>Gross Budget Discount:</th>
<th>Net Net Budget</th>
<th>Net eCPM</th>
</tr>
<tr>
<td><input class="stidinput" name="stidinput" type="text" /></td>
<td class="categoryinput"></td>
<td class="formatinput"></td>
<td class="exclusiveinput"></td>
<td>01/01/2015</td>
<td>01/01/2015</td>
<td class="cminput"></td>
<td></td>
<td></td>
<td></td>
<td class="rcinput"></td>
<td class="impsinput"></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<button id="addrowbtn">AddRow</button>
<button id="addpricebtn">AddPrice</button>
用户应该能够添加行和填充在细胞与类: stidinput,之后用户点击按钮,该按钮将以JSON格式从数据库中检索费率。我需要找到一种方式,jQuery脚本检索所有STID,并填写在从数据库中获得相应的信息,而不是只有第一个...
感谢,
请问您可以编辑您的问题并清楚解释问题吗? – dario 2014-12-27 17:33:53
'var inputer = this.value;'|| 'data:this.id,'???这是真的不清楚你在问什么... – 2014-12-27 17:38:00
我认为inputer必须定义如下:'var inputer = $(this).val();'和数据以及:data:{id:inputer} ' – Banzay 2014-12-27 17:40:39