Dou*_*eux 13 firefox jquery click internet-explorer-8
我有这个点击监听器,由于某种原因它不会在IE8或Firefox中触发:
console.log("listener attached");
jQuery(".ui-button-text").click(function() {
console.log("this should have triggered");
var ajaxUrl = '/ajax.php?popup=true';
var dataString = "param="+param+"¶m2="+param2;
// contruct the ajax request
jQuery.ajax({
url: ajaxUrl,
dataType: 'json',
data: dataString,
beforeSend: function() {
jQuery(".ui-button-text").html("Saving...");
},
complete: function() {
jQuery(".ui-dialog-content").dialog("close");
},
success:function(response){
}
});
});
Run Code Online (Sandbox Code Playgroud)
所以我可以在控制台中看到"监听器附加",但我没有看到点击触发器,这在chrome中有效,我在这里做错了什么?
谢谢!
更新:我尝试过使用live("click",function()...而不是它不会触发
更新:所以另一个更新,我应该提到这个对话框的内容是通过一个单独的页面获取的.它加载了AJAX,这个动态加载的内容包含这个点击监听器.
更新:这是加载内容的代码,请注意我实际上并没有编写这段代码,所以我不完全理解为什么它按照这里的方式完成:
<!-- START OF NEW WINDOW POPUP -->
jQuery('.option_window').click(function(){
var url = jQuery(this).attr('href');
var title = jQuery(this).attr('title');
jQuery('<div />').dialog(
{
autoOpen: false,
width: 720,
title: "Manage Code",
modal: true,
buttons:{
"Save and Return":function() {
var self = this;
var popupForm = jQuery("form.submit_on_close");
//if( jQuery("form.submit_on_close").attr('action') != '#' || jQuery("form.submit_on_close").attr('action') != '') {
if(popupForm.attr('action') != '#' || popupForm.attr('action') != '') {
jQuery.ajax({
url: jQuery("form.submit_on_close").attr('action'),
dataType: 'json',
data: jQuery("form.submit_on_close").serialize(),
success: function(data) {
data = eval(data);
if(data.resp == "success") {
var obj = jQuery('#repl_activation_row');
obj.unbind('mouseover');
if( data.property_code > 0) {
if( obj.hasClass('codeoff') ) {
obj.removeClass('codeoff').addClass('codeon');
}
} else {
if( obj.hasClass('codeon') ) {
obj.removeClass('codeon').addClass('codeoff');
}
}
}
jQuery(self).dialog('close');
}
});
}
else
jQuery(self).dialog('close');
}
},
//title:title,
open: function(event, ui){
jQuery(".ui-dialog").delay(600).queue(function(n) {
var topPos = jQuery(".ui-dialog").offset().top;
var finalPos = topPos - (jQuery(".ui-dialog").height() / 3);
jQuery(".ui-dialog").css("top", finalPos);
n();
});
var self = this;
jQuery.getJSON(url, {}, function(data){
jQuery(self).html(data);
});
},
close: function(event, ui){ jQuery(this).dialog( "destroy" ); jQuery(this).remove(); }
}).dialog('open');
return false;
})
<!-- END OF NEW WINDOW POPUP -->
Run Code Online (Sandbox Code Playgroud)
这是链接:
<a href="/popupmanager.php?code=3212&client=4432" class="actions option_window menulink">Manage</a>
Run Code Online (Sandbox Code Playgroud)
Rob*_*b W 16
您的错误是由jQuery UIbutton()方法的错误实现/假设引起的.相关代码在下面显示和解释(请参阅答案的底部以获得修复):
HTML: <button id="save">Save and Return</button>
JavaScript: $("#save").button();
Run Code Online (Sandbox Code Playgroud)
此代码的输出如下:
<button id="save" class="ui-button ... ui-button-text-only" role="button" ..>
<span class="ui-button-text">Click me</span>
</button>
Run Code Online (Sandbox Code Playgroud)
如您所见,具有类的元素.ui-button-text是元素的子<button>元素.
现在,看看这个小提琴.几乎在每个浏览器中,小提琴都表明没有事件会触发<button>元素的子节点.
要修复代码,请使用jQuery(".ui-button-text").click(function() {以下任一方法替换:
jQuery(".ui-button").click(function() { // Recommended
jQuery(".ui-button-text").parent().click(function(){ // Alternative method
Run Code Online (Sandbox Code Playgroud)
检查这些方法的比较(小提琴),你会发现错误是由你错误的实现/假设jQuery UI插件引起的.
| 归档时间: |
|
| 查看次数: |
1460 次 |
| 最近记录: |