【发布时间】:2014-10-05 13:49:50
【问题描述】:
我将此行添加到 master.cs 页面。
<h4 class="hideAndShow">[ - ] Hide</h4>
在 CSS 文件中:
.hideAndShow
{
position: fixed;
top:120px;
right:420px;
color: white;
background-color:green;
}
然后在同一个 master.cs 页面中。
<script>
var hideShowBool = true;
$('.hideAndShow').bind('click', function ()
{
if (hideShowBool == true)
{
$(this).replaceWith('<h4 class="hideAndShow">[ + ] Show</h4>');
hideShowBool = false;
} else
{
$(this).replaceWith('<h4 class="hideAndShow">[ - ] Hide</h4>');
hideShowBool = true;
}
});
</script>
预期的行为: [ - ] Hide 文本应在 [ + ] Show 和 [ - ] Hide 之间切换。
但是发生的情况是它只响应第一次点击。其中 [ - ] Hide 被替换为 [ + ] Show。但是当再次点击它时;没有预期的效果。
问题出在哪里?以及如何解决?
【问题讨论】:
标签: javascript jquery css .net