Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何停止在jQuery中只显示值而只更新值?_Javascript_Jquery_Dom - Fatal编程技术网

Javascript 如何停止在jQuery中只显示值而只更新值?

Javascript 如何停止在jQuery中只显示值而只更新值?,javascript,jquery,dom,Javascript,Jquery,Dom,我试图阻止玩家再次获得新的值,而我只想更新数量 HTML <div class="playerTypeBlock" data-player-type-id="1" data-player-value="10.00"> <div class="heading">Ninja</div> <div class="price">$10</div> <a class="addToTeam" href="#">Add p

我试图阻止玩家再次获得新的值,而我只想更新数量

HTML

<div class="playerTypeBlock" data-player-type-id="1" data-player-value="10.00">
    <div class="heading">Ninja</div>
    <div class="price">$10</div> <a class="addToTeam" href="#">Add player</a>

</div>
<hr>
<div class="playerTypeBlock" data-player-type-id="2" data-player-value="20.25">
    <div class="heading">Samurai</div>
    <div class="price">$20.25</div> <a class="addToTeam" href="#">Add player</a>

</div>
<hr>
<table class="teams" border="1">
    <thead>
        <tr>
            <th>Players</th>
            <th>Quantity</th>
        </tr>
    </thead>
    <tbody class="totalPlayers"></tbody>
</table>
<div class="total"> 
 <span>Total: $</span>
 <span class="amount" id="totalvalue">0.00</span>
</div>

这条线有问题吗

$('table .totalPlayers').append(
'<tr><td>' + playerName + '</td>' + 
'<td>' + quantity + ' </td></tr>');
然后更新

$('#' + playerId + ' .quantity').html(New value here);

选中
数量
,如果是
1,则追加新行
,否则修改数量单元格:

if (quantity > 1) {
    $('table .totalPlayers').find('#player-' + playerId + ' .quantity').text(quantity);
}
else {
    $('table .totalPlayers').append('<tr id="player-' + playerId + '"><td>' + playerName + '</td><td class="quantity">' + quantity + ' </td></tr>');
}
if(数量>1){
$('table.totalPlayers').find('#player-'+playerId+'.quantity').text(quantity);
}
否则{
$('table.totalPlayers').append(''+playerName+''+quantity+'');
}

演示:静态播放器还是动态播放器?(忍者,武士)静态,我会在标记中包含所有与玩家相关的数据,并且不希望它发生变化。感谢这一点……我觉得我需要使用if语句,但不知道要检查的条件
$('#' + playerId + ' .quantity').html(New value here);
if (quantity > 1) {
    $('table .totalPlayers').find('#player-' + playerId + ' .quantity').text(quantity);
}
else {
    $('table .totalPlayers').append('<tr id="player-' + playerId + '"><td>' + playerName + '</td><td class="quantity">' + quantity + ' </td></tr>');
}