更改每个点击的.html

时间:2016-10-17 20:02:12

标签: php jquery html this each

这是我第一次尝试从头开始使用this,我不确定我是否理解正确。我正在尝试将其中<td>的{​​{1}}更改为点击时的+,反之亦然。 我没有得到任何错误,我不确定具体我做错了什么。点击没有任何反应。我在页面上有其他jquery工作正常。

-

html看起来像

echo "<script type'text/javascript'>
$('.plus_minus').each(function() {
    $(this).click(function(){
        if ($(this).html() == '+'){
            $(this).html = '-';
        }
        else {
            $(this).html = '+';
        }

    })
 });

</script>";

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

$('.plus_minus').each(function() {
   $(this).click(function(){
        if ($(this).text() == '+'){
            $(this).text('-');
        }
        else {
            $(this).text('+');
        }

   })
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr align="right" class="loc"><td class="plus_minus" width="20" align="center" 
            bordercolor="#000000"
            style="cursor:pointer;font-size:10pt;font-weight:bold;
            border-style:solid;border-width:1pt">+</td>
</tr>
</table>