简单的Javascript问题 [英] Simple Javascript question

查看:138
本文介绍了简单的Javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击按钮时,第一次,一切正常,但第二次,没有任何反应。为什么会这样?

When I click on the button, the first time, everything works fine, but the second time, nothing happens. Why is that?

<form name="alert"><input type="text" name="hour"><input type="text" name="min"><input type="button" value="ok" onclick="budilnik(this.form)">

<script type="text/javascript">
function budilnik(form)
{

budilnik=1;
min=form.min.value;
hour=form.hour.value;
alert (min+' '+hour+' '+budilnik);

}
</script>


推荐答案

学习使用 Firebug 。它将在未来帮助你。

Learn to use Firebug. It'll help you immensely in the future.

budilnik=1;

这可能听起来很疯狂,但这是重新定义函数budilnik到整数,它打破了你的窗体的onlick。如果你在关键字 var 前面加上这个语句,你将会影响这个函数但不会覆盖它。当你没有指定 var 关键字时,变量被认为是全局作用域,这可能会导致问题(像这样)。

This may sound crazy, but this is redefining the function budilnik to an integer, which breaks your form's onlick. If you preface this statement with keyword var, you will shadow the function but not overwrite it. When you do not specify the var keyword, variables are assumed to be global scope, which can cause issues (like this).

我用firebug看到第二次点击时,budilnik没有定义。如果您使用过此工具,则可能自己调试此问题。

I used firebug to see that on the second click, "budilnik is not defined." If you had used this tool, you could have probably debugged this issue yourself.

这篇关于简单的Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆