开发者

Using srcElement in Firefox

I have a problem in Firefox. I can't use window.event.srcElement.id in Firefox and flow code doesn't work in Firefox. Please help me.

$(document).ready(function(e) {
    $("img[rel]").ove开发者_JAVA百科rlay(function() {
        try {
            if (window.event) {
                var sid = window.event.srcElement.id;
                document.getElementById("SelectedNewsID").value = sid;
            }
            else {
                //alert("Error.");
            }
        }
        catch (err) {
            alert("Error");
        }
    });
});


window.event.srcElement works only in IE. For all other browsers window.event does not work. If you are using JQuery to bind the click event or any other event you will get the event object in which event.target will give you the target element.


Try this

$(document).ready(function(e) {
    $("img[rel]").click(function(e){
       $("#SelectedNewsID").val(e.target.id);
    }).overlay();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜