开发者

what's wrong with this jQuery method?

I have this method:

function replaceRightClickIcefacesMethod() {
    var oldName = jQuery(".singlePaneOfGlassBlock").attr("oncontextmenu");
    oldName = oldName.replace('Ice.Menu.contextMenuPopup', 'contextMenuPopupUpdated');

    jQuery(".singlePaneOfGlassBlock").attr("oncontextmenu", oldName);
}

I do not understa开发者_开发百科nd why Firebug reports:

oldName.replace is not a function

Do you see any issue? For me it's just weird...

UPDATE: Just notice that oldName returns a function, if I do alert(oldName):

function oncontextmenu(event) {
Ice.Menu.contextMenuPopup(event, "j_id88:sectionContextMenu_sub", "j_id88:j_id111:0:j_id123:0:j_id124");
return false;

}


Before jQuery 1.6, jQuery(".singlePaneOfGlassBlock").attr("oncontextmenu") returns a function as it returns the property of the DOM element and not the attribute (DEMO).

This is fixed in jQuery 1.6 (DEMO).

If you cannot use jQuery 1.6, you have to call getAttribute on the DOM element:

var oldName = jQuery(".singlePaneOfGlassBlock")[0].getAttribute('onclick');


Check if oldName is null...


Maybe remove assignation in third line? Replace may return number of entries replaced.

function replaceRightClickIcefacesMethod(){
  var oldName = jQuery(".singlePaneOfGlassBlock").attr("oncontextmenu");
  oldName.replace('Ice.Menu.contextMenuPopup','contextMenuPopupUpdated');

  jQuery(".singlePaneOfGlassBlock").attr("oncontextmenu",oldName);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜