Jquery - 一个函数的多个条件语句
Jquery - multiple conditional statements for one function
我有一个弹出窗口 window,如果在 Iframe 上点击我的网站 或 ,则需要将其隐藏。
我想做的是写一个这样的方法:
if(click on my site || click on Iframe){
hide window
}
我试过这段代码,但它不起作用:
if($(document).click()===true || $("#clientframe").contents().find(document)===true)(function(){
$("#img-window").hide();
});
您将两种方法作为条件。我会尽可能避免这种情况。方法 returns 在 javascript 中可能非常棘手。查找 javascript 真相 table
https://dorey.github.io/JavaScript-Equality-Table/
而是使用您的方法中更具体的 returns。像
$("#identifier").method()(function(){
execute code here
return true;
});
这样当您在 if 语句中检查结果时,您就会知道会发生什么。
你的问题完全错误。函数调用是语句。您不能将语句作为条件。除了它 returns 东西。他们是事件调用。所以 if 条件没有合适的地方。使用 AND 或 OR 运算符并不重要。如果您想在单击 html 元素时隐藏某些内容。做这样的事情。
HTML
<button id='mysite' onclick='hided()'></button>
<button id='iframe' onclick='hided()'></button>
JAVASCRIPT
function hided()
{
// hide that dialog
}
我有一个弹出窗口 window,如果在 Iframe 上点击我的网站 或 ,则需要将其隐藏。 我想做的是写一个这样的方法:
if(click on my site || click on Iframe){
hide window
}
我试过这段代码,但它不起作用:
if($(document).click()===true || $("#clientframe").contents().find(document)===true)(function(){
$("#img-window").hide();
});
您将两种方法作为条件。我会尽可能避免这种情况。方法 returns 在 javascript 中可能非常棘手。查找 javascript 真相 table
https://dorey.github.io/JavaScript-Equality-Table/
而是使用您的方法中更具体的 returns。像
$("#identifier").method()(function(){
execute code here
return true;
});
这样当您在 if 语句中检查结果时,您就会知道会发生什么。
你的问题完全错误。函数调用是语句。您不能将语句作为条件。除了它 returns 东西。他们是事件调用。所以 if 条件没有合适的地方。使用 AND 或 OR 运算符并不重要。如果您想在单击 html 元素时隐藏某些内容。做这样的事情。
HTML
<button id='mysite' onclick='hided()'></button>
<button id='iframe' onclick='hided()'></button>
JAVASCRIPT
function hided()
{
// hide that dialog
}