javascript - jQuery .live ('click' ) 没有按预期工作

标签 javascript jquery

我正在尝试设置下面的 emblem-important.png 所以当你点击这个项目时,它会忽略带有 .editable 监听器的父元素并且只使用我分配给它的那个。下面的代码在 Chrome 中运行良好,但在 IE 8 中效果不佳。它在 IE 8 中不起作用,我需要它。在不使用 onClick() 的情况下,我不确定在 IE 8 中设置它的最佳方法。如果我可以在 JS 中使用监听器设置它会容易得多...

<div class="cell editable" style="float:left;width:99%; font-weight:bold; font-size:16pt; padding-bottom:50px" data-fieldid="684709" data-fieldname="Product Name">
     <span id="sob_form_span_684709"><strong>Freedom Communications: Choice PPO</strong><img src="/img/emblem-important.png"></span>
</div>
//toggle the form status
jQuery('#formStatus').change(function () {
    jQuery.get('/products/ajax_updateStatus/'+Page.formId+'/'+jQuery(this).val()+'/', {}, function () {
        notify('check', 'Status has been updated');
    });
});

jQuery('.editable').live('click', function () {
    var urlPieces = (document.location+'').split('/');
    jQuery.fancybox({
        'href': urlPieces[0]+'/'+urlPieces[1]+'/'+urlPieces[2]+'/'+urlPieces[3]+'/update_form_field/'+jQuery(this).attr('data-fieldId'),
        'title': jQuery(this).attr('data-fieldName'),
        'autoDimensions': false,
        'margin': 0,
        'padding': 15,
        'width': '768',
        'scrolling': 'auto',
        'height': jQuery(window).height() - 100,
        'onComplete': function() {
            jQuery("#fancybox-title").css({
                'top':'-10px',
                'bottom':'auto'
            });
        }
    });
});

jQuery('img[src=/img/emblem-important.png]').live('click', function (e) {
    e.stopPropagation();
    if (confirm('Are you sure you want to restore this field to its original content?')) {
        var locSplit = (document.location+'').split('/'),
            id = jQuery(jQuery(e.currentTarget).parent()).attr('id'),
            fieldId = jQuery(this).closest('td').attr('data-fieldId');
        jQuery.get('/customs/revertField/'+locSplit[locSplit.length-1]+'/'+fieldId, function (r) {
            jQuery('#'+id).html(r.fieldValue);
        }, 'json');
    }
});

最佳答案

一些浏览器会将 src 属性扩展为实际用于请求图像的 URL。

使用 attribute ends with selector应该解决这个问题:

img[src$=/img/emblem-important.png]

关于javascript - jQuery .live ('click' ) 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7854673/

相关文章:

php - ajax - 使用 onload 和 onunload 启动和结束 session

javascript - 多维数组排序顺序跨浏览器兼容 "natural case"

javascript - 是否允许 JS 引擎更改 NaN 的位?

javascript - 我错过了什么吗?我的值没有存储到我的数组中

javascript - 结果结束后如何停止 slider 滑动 $.each 循环

javascript - 如何使用 jQuery 从 Web Worker Thread 中解析 XML

javascript - 使用 Comet 长轮询在 Ext JS 中更新模型和存储

php - 向 PHP 表单添加更多字段(用户可以添加多个地址)

javascript - 根据 getJSON 数据的响应显示图像

javascript - 处理动态填充表中新内容的简便方法?