输入的选择器的jquery到TD

问题描述 投票:0回答:2

你好,我有类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('&nbsp;') > -1)
{
var newValue = html.replace('&nbsp;', '');
$("tr.forc td.TdbeforeForcage input.numberforce").val(newValue);
}
});
javascript jquery html
2个回答
0
投票

你的问题可能是线

$("tr.forc td.TdbeforeForcage input.numberforce").val(newValue);

你得到newValue但随后将其设置为类numberforce的所有投入,解决它,你应该引用td自我,然后更改新添加的输入,像这样:

$(this).find('input.numberforce').val(newValue)


0
投票

$( “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)); });

© www.soinside.com 2019 - 2024. All rights reserved.