开发者

Using srcElement in Firefox

开发者 https://www.devze.com 2023-03-17 23:05 出处:网络
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.

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

精彩评论

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

关注公众号