我有一个页面,通过jQuery动态地将SVG添加到页面:
grid.append($('<object>')
.load(function () {
// do stuff
alert('loaded')
})
.attr({
id: 'tile',
type: 'image/svg+xml',
width: Math.round(tile_w),
height: Math.round(tile_h),
data: 'map/base.svg'
})
);
Run Code Online (Sandbox Code Playgroud)
我需要访问SVG文档(将一个变量"推"到svg脚本上下文中),但必须为此加载SVG.我的问题是我没有让load事件工作.没有显示警报.
怎么做?
编辑:似乎jQuery只是阻止将"加载"事件绑定到非图像或文档元素,所以我只使用"官方"addEventListener()函数(不支持愚蠢的IE,但这不是问题为了我):
grid.append($('<embed>')
.attr({
id: 'tile' + i,
type: 'image/svg+xml',
width: Math.round(tile_w),
height: Math.round(tile_h),
src: 'map/base.svg'
})
.css({
position: 'absolute',
left: Math.round(p.x),
top: Math.round(p.y)
}).each(function (i){
this.addEventListener ('load', function (e) {
alert('loaded')
})
})
);
Run Code Online (Sandbox Code Playgroud) 我想在我的项目中使用Jetbrains @ Nullable/@NotNull Annotations.

我有一个带有@NotNull字段的类.构造函数自然不接受,null而是抛出异常.当然,这个构造函数的参数也可以用@NotNull注释.
为什么IntelliJ IDEA会抱怨空检?文件说明:
使用NotNull声明的元素声明null值被禁止返回(对于方法),传递给(参数)并保持(局部变量和字段).
但是我仍然需要在运行时检查null值,以防构建系统不理解Annotation并接受类似的语句new Car(null).我错了吗?