【发布时间】:2019-06-14 21:41:36
【问题描述】:
这里是新手。当 div #valor 高度大于 50px 时,我正在尝试使用 window.location.replace 更改网站的页面/网址。
详情:
此 div #valor 会在每次点击时增加其高度。但是当它达到至少 50px 时,我需要将用户重定向到另一个页面。
我尝试了很多不同的方法,但我知道每种方法都缺少一些东西。我将在下面列出它们以供参考。我确实认为问题在于我构建代码的方式......
var maskHeight = $("#valor").css('height');
if (maskHeight > 50){
window.location.replace("https://google.com");
}
else {
alert("if I'm here it means it didn't work"); //just testing
}
});
我有很多不同的选项都不起作用,但它们都有这个 if 语句:
if ($('#valor').height() > 40) {
window.location.replace("https://google.com");
}
我也试过这样的:
var div = $("#valor").height();
var win = 50;
if (div > win ) {
window.location.replace("https://google.com");
}
我的第一种方法(未在此处列出)不起作用,因为它在第一次点击时比较了值。我只想做这样的事情:当#valor height 大于/达到 50px > 更改 url。
提前感谢您!非常感谢任何帮助。
【问题讨论】:
-
那么代码只在第一次调用时运行。如果元素正在被其他东西调整大小,它将不会被调用。那么当它改变时你会以某种方式调用它吗?
标签: javascript jquery html url height