错误:无法读取属性'defaultView'的未定义,使用jQuery
Error: Cannot read property 'defaultView' of undefined, using jQuery
我有这样的代码
$(document).ready(function (){
var Form_addTurbo = $('form#Form_addTurbo');
Form_addTurbo.submit(function (e){
e.preventDefault;
v = new Notification('Creating Turbo.', 'information', 'Working..', function(){return;});
$.post('/api/turbos/new.php', {
action : 'createNew'
}, function (r){
v.hide();
if(r.success){
new Notification('Turbo Create.', 'saved', '', function(){return;});
}else if(r.error){
}else{
new Notification('Something went wrong.', 'error', '', function(){return;});
}
}, 'json');
return false;
});
});
使用这个api
$(document).ready(function(e) {$("body").prepend('<ul id="notifications"></ul>');});
/**
* Global notification system
*
* @param String Message to be displayed
* @param String Type of notification
*
* @author Bram Jetten
* @version 28-03-2011
*/
Notification.fn = Notification.prototype;
function Notification(value, type, tag, onclickfunc) {
this.log(value, type);
this.element = $('<li><span class="image '+ type +'"></span>' + value + '</li>');
if(typeof tag !== "undefined" && tag !== '') {
$(this.element).append('<span class="tag">' + tag + '</span>');
}
if(typeof onclickfunc == 'function'){
this.element.click(onclickfunc);
}
$("#notifications").append(this.element);
this.show();
}
/**
* Show notification
*/
Notification.fn.show = function() {
$(this.element).slideDown(200);
$(this.element).click(this.hide);
}
/**
* Hide notification
*/
Notification.fn.hide = function() {
$(this).animate({opacity: .01}, 200, function() {
$(this).slideUp(200, function() {
$(this).remove();
});
});
}
/**
* Log notification
*
* @param String Message to be logged
* @param String Type of notification
*/
Notification.fn.log = function(value, type) {
switch(type) {
case "information":
console.info("*** " + value + " ***");
break;
case "success":
console.log(value);
break;
case "warning":
console.warn(value);
break;
case "error":
console.error(value);
break;
case "saved":
console.log(value);
break;
default:
console.log(value);
break;
}
}
所以发生的事情是,我试图关闭通知使用隐藏功能,我相信它给出,但我得到这个错误。
Uncaught TypeError: Cannot read property 'defaultView' of undefined
我相信它不知道"this"是什么,但我如何才能让它工作
对您的示例做了一些小的更改。试试吧http://jsfiddle.net/FLE39/
仔细看了一下你的代码,做了一个新的jsfiddle。
如果你在后端node.js中使用这个,那么这个错误就会出现,而不是使用node-html-to-image
相关文章:
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- 当null应该在javascript中使用而不是未定义时
- 得到"未定义不是函数“;使用显示原型图案时出错
- 使用javascript ajax post方法的未定义偏移PHP错误
- Ember服务在注入组件并在计算属性中使用后是未定义的
- “未定义”使用 Rails 对象传递数据属性
- 变量 未定义 使用 alert()
- 未定义使用 HTTP GET 请求返回对象
- JavaScript 运行时错误:“$”未定义 - 使用 MVC 4
- TypeError:无法读取属性'绑定'的未定义使用ng-croper指令
- Array.prototype.values()未定义-使用Babel在NodeJS环境中转换ES6
- 会话未定义-使用Connect Redis/ExpressJS/Node
- d3.csv vs d3.json:无法读取属性'长度'的未定义使用JSON数据
- 选择2显示未定义使用initSelection ajax调用
- Event.target.id未定义?使用backbone.js创建动态按钮
- 未定义使用Javascript->Actionscript
- D3.js:通过 d3 加载平面一维数组.csv导致“类型错误:组数据未定义”/使用 D3.js 加载多个 CSV 文件
- 未捕获的类型错误:不能调用方法'未定义使用Ckeditor