你好,我有类TdbeforeForcage的TD以及它我增加了一个输入一个值,以使TD值可编辑,所以我有所有的TD值具有相同数目的问题,但每个输入应该采取TD的价值。
我在这里的HTML:
<tr class="forc" style="font-size : @fontSize; font-weight: @fontWeight;">
<td style="font-size:14px;text-align:left;">@ech.Key.Titre</td>
@foreach (var x in ech.Value)
{
if (x == "<BR>")
{
<td style="font-size:14px;text-align:right">-</td>
}
else if (x == "-")
{
<td style="font-size:14px;text-align:right">@x</td>
}
else if (counter == counterTotal)
{
<td style="font-size:14px;text-align:right">@x</td>
}
else if (x.Contains("/"))
{
<td style="font-size:14px;text-align:left">@x</td>
}
else if (counter != counterTotal && x != "-" && isforcagerevision)
{
<td class="forcage" style="font-size:14px;text-align:right;">
</td>
}
else
{
<td class="TdbeforeForcage" style="font-size:14px;text-align:right">@x</td>
}
counter++;
}
</tr>
在这里我的JS我想我已经在选择一个问题:
$("tr.forc td.TdbeforeForcage").each(function () {
var html = $(this).html();
var input = $('<input class="numberforce" style="width:50%" type="text" />');
input.val(html);
$(this).html(input);
if (html.indexOf(' ') > -1)
{
var newValue = html.replace(' ', '');
$("tr.forc td.TdbeforeForcage input.numberforce").val(newValue);
}
});
你的问题可能是线
$("tr.forc td.TdbeforeForcage input.numberforce").val(newValue);
你得到newValue
但随后将其设置为类numberforce的所有投入,解决它,你应该引用td
自我,然后更改新添加的输入,像这样:
$(this).find('input.numberforce').val(newValue)
$( “tr.forc td.TdbeforeForcage”)。每个(函数(){
VAR HTML = $(本)的.html();
VAR输入= $('<input class="numberforce" style="width:50%" type="text" />');
input.val(HTML);
$(本)。html的(输入);
$(本).find( 'input.numberforce')VAL($修剪(HTML));
});