【发布时间】:2017-02-26 22:16:43
【问题描述】:
这是我第一次尝试从头开始使用this,我不确定我是否理解正确。我正在尝试将其中包含+ 的<td> 更改为单击时的-,反之亦然。
我没有收到任何错误,我不确定我做错了什么。点击没有任何反应。我在页面上还有其他运行良好的 jquery。
echo "<script type'text/javascript'>
$('.plus_minus').each(function() {
$(this).click(function(){
if ($(this).html() == '+'){
$(this).html = '-';
}
else {
$(this).html = '+';
}
})
});
</script>";
html 看起来像
echo '<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>';
任何帮助将不胜感激!
【问题讨论】:
-
1.打开开发者控制台。 2.
$(this).html('-'); -
您正在尝试为曾经的 .plusminus 类分配一个点击处理程序,这是错误的做法。您应该有一个处理程序来处理所有这些,例如
$(.plus_minus).on('click', function(e) { $(this).html ... }); -
@MarcB 我把它改成了
$('.plus_minus').on('click', function(e) {,然后我上面的,还是不行