浏览器兼容性问题 - 无法在 IE 上运行
Browser compatability issue -NOt working on IE
我的工作有一个问题,在Firefox和Google Chrome上效果很好,但在IE中不起作用。你能指出我哪里做错了吗?
脚本.js
$(document).ready(function () {
$('.delete').click(function () {
var contentId = $(this).attr('contentid');
$.confirm({
'title': 'Delete Confirmation',
'message': 'Are you sure you want to delete this record?',
'buttons': {
'Yes': {
'class': 'blue',
'action': function () {
DoDelete(contentId);
}
},
'No': {
'class': 'orange',
'action': function () {}
// Nothing to do in this case. You can as well omit the action property.
},
'close': {
'action': function () {}
// Nothing to do in this case. You can as well omit the action property.
}
}
});
});
});
确认脚本以生成 HTML 标记
(function ($) {
$.confirm = function (params) {
if ($('#confirmOverlay').length) {
return false;
}
var buttonHTML = '';
$.each(params.buttons, function (name, obj) {
buttonHTML += '<a href="#" class="button ' + obj['class'] + '">' + name + '<span></span></a>';
if (!obj.action) {
obj.action = function () {};
}
});
var markup = [
'<div id="confirmOverlay">',
'<div id="confirmBox">',
'<div id="header">',
'<div id ="title">',
params.title,
'</div></div>',
'<div id ="textbox">',
'<p>',
params.message,
'</p></div>',
'<div id="confirmButtons">',
buttonHTML,
'</div></div></div>'
].join('');
$(markup).hide().appendTo('body').fadeIn();
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons, function (name, obj) {
buttons.eq(i++).click(function () {
obj.action();
$.confirm.hide();
return false;
});
});
}
$.confirm.hide = function () {
$('#confirmOverlay').fadeOut(function () {
$(this).remove();
});
}
})(jQuery);
首先,$('.delete')
处理程序的第一行是:
var contentId = $(this).attr('contentid');
但您的.delete
标记是:
<div class="delete"></div>
(请注意缺少contentId
属性)。 幸运的是(?)您的代码实际上似乎并没有使用contentId
:-)
更相关的是,您需要确定代码的哪一部分正在损坏(如果您有代码的JS小提琴,我可以查看,但是由于您没有,因此您必须自己找出)。 我会在调用$.confirm
之前放一个alert
,然后在$.confirm
中再次放置,以确保代码甚至到达您的插件(如果没有,那就是您的问题)。
如果是,下一个要问的问题是"你的标记是否被添加,但没有显示,或者它根本没有被添加"。 警报或 IE 开发人员工具应该允许您检查 DOM 并找出是否添加了标记;如果没有,那就是你的问题。 如果它正在添加,但没有显示,那么您的fadeIn
出了问题,这就是您的问题。
最后,有一种更简单的方法可以挂接按钮事件;而不是:
var buttons = $('#confirmBox .button'),
i = 0;
$.each(params.buttons, function (name, obj) {
buttons.eq(i++).click(function () {
obj.action();
$.confirm.hide();
return false;
});
});
你可以做:
$('#confirmBox .button').each(function(button) {
$(button).click(function () {
params.buttons[$(this).text()].action();
$.confirm.hide();
return false;
});
});
相关文章:
- Javascript赢得'不能在IE上编译,但可以在Chrome上运行
- 以下颜色更改功能在IE9和Firefox中运行良好,但在早期的IE或Chrome中则不然
- Javascript'元素'在ie中未定义,但在chrome和firefox中运行良好
- 通过运行条件编译防止JS泄露IE浏览器
- 是否可以从在Firefox或IE的网页中运行的Javascript启动Windows进程
- 没有在带有IE-FF的IFrame中运行的脚本是可以的
- jQuery fadeIn fadeOut"眨眼;在Chrome上,在FireFox和IE上运行良好
- SP2007使IE在运行jssor代码时挂起
- Jquery没有在firefox浏览器中调用Webservice方法,它在Chrome和IE中运行良好
- 长时间运行的脚本IE与Chrome/Firefox
- dart2js编译的Polymer Dart应用程序未在IE 11中运行
- 从Java脚本返回多个值,这些值不能在firefox上运行(在IE上运行良好)
- 内容编辑器 Web 部件脚本不在 IE 11 中运行(如果开发人员工具处于打开状态,则运行)
- JavaScript运行时错误:应为':'在IE中
- 在IE中没有开发人员控制台的情况下,JavaScript无法运行(can't属性为缺少控制台)
- 浏览器兼容性问题 - 无法在 IE 上运行
- 脚本在除IE之外的所有其他浏览器中都能完美运行
- Jquery对话框在IE中完美运行,但在FF和Chrome中则不然
- 强制仅限数字的js函数不'不适用于Firefox,但适用于Chrome;IE运行良好
- Will The Mark of The Web始终确保IE运行本地HTML文件