为什么在asp.net中调用javascript函数时需要分号 [英] Why is the semicolon required while calling a javascript function in asp.net

查看:57
本文介绍了为什么在asp.net中调用javascript函数时需要分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我没有尝试;服务器显示错误。

为什么最有必要让函数不用分号调用



考虑我有javascript代码为

函数myfunction(){

//代码部分

}







< asp:RadioButtonList ID =rblistGenderrunat =serveronclick =myfunction();>





为什么需要onclick方法的分号?



我必须在用户时执行我的代码更改单选按钮列表的值。

When I tried without ; the server shows error.
Why is it most necessary so that function doesn't call without semicolon

Consider I am having javascript code as
function myfunction(){
// code part
}



<asp:RadioButtonList ID="rblistGender" runat="server" onclick="myfunction();">


Why the semicolon at the onclick method is needed?

I have to execute my code whenever the user changes the value of the radio button list.

推荐答案

为什么用句号结束​​句子并以大写字母开头?所以我们知道你的句子何时开始和结束。同样的原因,js喜欢看到一个分号,它告诉它这是最后的陈述。我认为很多js实现都不需要;但是对于启动代码段的事情来说最重要的是。



Why do you end sentences with a period and start them with a capital letter? So we know when your sentences begin and end. Same reason that js likes to see a semi-colon, it tells it this is the final statement. I think a lot of js implementations don't require the ; but it is most important when it comes to things that start code segments.

if (x == 1)
   x = x + 1;





如果x为1,则上述意味着增加x





The above means increment x if x is 1.

if (x == 1);
   x = x + 1;





上述意味着如果x为1则什么都不做。然后总是增加x。



作为最佳实践,你应该总是使用它们。



The above means that if x is 1 do nothing. Then always increment x.

As best practice you should always use them.


这篇关于为什么在asp.net中调用javascript函数时需要分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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