【发布时间】:2018-10-10 04:30:27
【问题描述】:
我在下面的 jQuery 脚本中有一个名为 toggleBool 的变量和一个名为 toggleBool 的函数。
它可以工作,除了变量 toggleBool 不会在每次单击调用 toggleBool() 的按钮时在真假之间改变。如果我将变量名更改为例如toggleBoolean,然后一切正常。另外,我正在使用 alert() 进行跟踪。有没有工具可以让我在 jQuery 或 javascript 中插入断点?
toggleBool = false;
iter_n = 0;
jQuery('#pResult').css(
{ 'font-size' : '20px',
'background-color' : "#fff8dc" ,
})
$('#clickMe').css(
{ "background-color" : "#e9ffdb",
"font-size" : "30px",
"font-family" : "Courier",
"font-style" : "italic",
})
jQuery('#clickMe').click(function()
{
toggleBool();
if (toggleBool == true)
$('#fColor').css('color', 'magenta');
else
$('#fColor').css('color', 'blue');
$('#pResult').html('You just clicked the event button ' + iter_n + '-th time!')
function toggleBool()
{
iter_n++;
toggleBool = !toggleBool;
}
})
<button id='clickMe'>Click the button to toggle color</button>
<h2 align=center>
<p>There are so many <span id='fColor' style="color:blue">colorful</span> flowers.</p>
</h2>
<p align=center id='pResult'> This is the default paragraph before click event. </p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
【问题讨论】:
-
在第一个
click之后,toggleBool变量在toggleBool = !toggleBool;行中变为布尔变量。所以它不应该工作。
标签: jquery