检查 javascript 中的零参数和空白字符串
这是我的代码:
JustAName.prototype = {
statusColoring: function(idx){
if (idx != ""){
alert ("1st alert");
}else{
alert ("2nd alert");
}
}
当我使用 statusColoring(0) 调用 statusColoring 函数时,为什么我没有收到第一个警报?但是当我使用 statusColoring(1) 调用时,我收到第二个警报?
将零参数传递给函数并检查它的正确方法是什么?或者如何检查零/空白参数?
我已经使用 idx.length 但仍然不能..
谢谢:)
This is my code:
JustAName.prototype = {
statusColoring: function(idx){
if (idx != ""){
alert ("1st alert");
}else{
alert ("2nd alert");
}
}
when I call statusColoring function using statusColoring(0), why I don't get 1st alert? but when I call using statusColoring(1) I get 2nd alert?
how is the correct way to pass zero parameter to a function and check it? or how to check the zero/blank parameter?
I have done using idx.length but still can not..
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个。
字符,长度相同,对应的字符相同
职位。
相同的数值)。 NaN 不等于任何东西,包括 NaN。
正零和负零彼此相等。
错误的。
Try this.
characters, same length, and same characters in corresponding
positions.
the same number value). NaN is not equal to anything, including NaN.
Positive and negative zeros are equal to one another.
false.
因为
0 != ""
返回false
。我认为你应该这样做:
Because
0 != ""
returnsfalse
.I think you should just do with: