var count=0;
function showIt(){
if(count==0){
alert(count);
count++;
}
alert(count);
}
Run Code Online (Sandbox Code Playgroud)
这个函数是onclick的一个事件,我第一次点击按钮时,我收到了警告0和1,但是当我继续点击时,"1"的语句没有改变.我不知道它为什么不改变,我试过count = count + 1,count + = 1,它们都不起作用.
因为你只在count == 0时递增
if(count==0){
alert(count);
count++;
}
Run Code Online (Sandbox Code Playgroud)
你的意思是
var count=0;
function showIt(){
if(count==0){
alert(count);
}
count++;
alert(count);
}Run Code Online (Sandbox Code Playgroud)
<button onclick="showIt()">showIt</button>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69 次 |
| 最近记录: |