我有一个URL,我想在FancyBox(或任何其他叠加类型弹出窗口)中打开.我不知道URL是否好,所以我想测试一下.如果无效 - 我不会将fancyBox插件附加到该特定URL,它将只是一个常规链接.如何在插入插件之前测试URL?尝试做类似的事情:
$("a.overlay").each(function() {
var xhr = $.get(this.href, function(data, status) {
// never executed in case of a failed request
});
if (xhr.status && xhr.status === 404)) {
// not good, do nothing
} else {
// can attach plugin here
}
});
Run Code Online (Sandbox Code Playgroud)
问题是,xhr并不总是定义,因为JS不等待请求完成.类似地,我不能使用回调函数,因为它似乎没有执行,以防请求失败(我可以在Firebug中看到它,但这不是很有用).
谢谢,祝大家周末愉快.
我是JavaScript的新手,因为我来自强类型语言,所以我选择了TypeScript.
我想知道发生了什么变量red在Red getter这个代码.它会在每次调用时重新创建(如in Green getter)还是每次创建一次并使用?哪个最好?
class Color {
public R: number;
public G: number;
public B: number;
public A: number;
static get Red(): Color {
var red = new Color(255, 0, 0);
Color.Red = function() { return red; }
return red;
}
static get Green(): Color {
return new Color(0, 255, 0);
}
constructor(red: number, green: number, blue: number, alpha: number = 255) {
this.R = red;
this.G = green;
this.B = blue;
this.A = …Run Code Online (Sandbox Code Playgroud) 我想data-index在其(嵌套)子节点之一上设置父元素的值.期望的结果:字符串"index"应该出现在h2.heading.
标记:
<div class="foo" data-index="index">
<div>
<h2 class="heading"><span>title</span></h2>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS(第一条data-index规则有效 - 但不是在正确的地方):
div.foo[data-index] .heading span {
display: none;
}
div.foo[data-index]::after {
content: attr(data-index);
color: green;
}
div.foo[data-index] .heading::after {
content: attr(data-index);
color: red;
border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)
我尝试在我的index.js.
完整错误:
class Clear extends Moderation {
^
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (C:\Users\Chigu\SoftKr\Asuha-Discord-Universal-Bot\Src\Actions\Moderation\Commands\Clear.js:5:21)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\Users\Chigu\SoftKr\Asuha-Discord-Universal-Bot\Src\Actions\Moderation\Moderation.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
清除.js
const Discord = require("discord.js");
const {Moderation} = require("../Moderation");
class Clear extends Moderation {
constructor(message, client) {
super(message, client);
this.command = "clear";
} …Run Code Online (Sandbox Code Playgroud) javascript ×2
ajax ×1
class ×1
css ×1
css3 ×1
discord.js ×1
extends ×1
jquery ×1
node.js ×1
typescript ×1