Javascript if (j === null) 什么都不做

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2756923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:48:00  来源:igfitidea点击:

Javascript if (j === null) do nothing

javascripthtml

提问by Kyle

I'm using CurvyCornersto make my corners curvy in IE, only thing is that when it reads the CSS it takes all the webkit properties and shows me an alert curvyCorners.alert("No object with ID " + arg + " exists yet.\nCall curvyCorners(settings, obj) when it is created.");.

我正在使用CurvyCorners使我的角在 IE 中弯曲,唯一的问题是当它读取 CSS 时,它会获取所有 webkit 属性并向我显示警报curvyCorners.alert("No object with ID " + arg + " exists yet.\nCall curvyCorners(settings, obj) when it is created.");

How can I just set this if statement to do nothing?

我怎样才能将这个 if 语句设置为什么都不做?

if (j === null)
  do nothing(); //but in real script

Thanks :)

谢谢 :)

回答by Delan Azabani

Do you have access to the code? If so, you can add this code to the start of the curvyCorners function definition:

您可以访问代码吗?如果是这样,您可以将此代码添加到 curvyCorners 函数定义的开头:

if (!obj) return;

This will quit the curvyCorners function silently if the element doesn't exist.

如果元素不存在,这将静默退出 curvyCorners 函数。

回答by icio

I would recommend

我会推荐

if (j !== null) doSomething();

And Kooilnc is probably correct: curvyCorners is probably saying that can't find the element because the DOM hasn't finished loading yet. I would combat that problem with

Kooilnc 可能是正确的:curvyCorners 可能说找不到元素,因为 DOM 还没有完成加载。我会用

window.onload = function()
{
    var obj = document.getElementById("corneredObj");

    if (obj !== null) {
        curvyCorners(settings, obj);
    }
}

回答by Tomarinator

I used this

我用过这个

if (j === null)
   1=1;

回答by KooiInc

It may be an idea to call the script after the DOM is loaded. Most of the times you can achieve this by placing the script tag at the bottom of your html document, right before the closing body tag (</body>).

在加载 DOM 之后调用脚本可能是一个想法。大多数情况下,您可以通过将 script 标签放在 html 文档的底部,就在结束正文标签 ( </body>)之前来实现这一点。

回答by Богуслав Павлишинець

If you really need to do nothing -=> this is the best way void(0)

如果你真的什么都不用做 -=> 这是最好的方法 void(0)