window.event javascript code does not work in Firefox

前端 未结 2 1553
你的背包
你的背包 2021-01-28 22:02

I have an markup

            
相关标签:
2条回答
  • 2021-01-28 22:16

    Firefox doesn't support windows.event object. Use these variables to store the value and it will work after that use your code:

    var event = e || window.event
    var assumed = (event.target || event.srcElement).id;
    
    0 讨论(0)
  • 2021-01-28 22:29

    try this:

    Tested and 100% working

    You can Combine here event and this(element)

    function postBackByObject(e,d) {
                var target = e.target || e.srcElement;     // Support IE6-8
    
                if (d.id == 'uploadControl') {
    
                    document.getElementById('labelId').click();
                }
                target.cancelBubble = true;
            }
    
    
    <div id="uploadControl" class="fileUpload1" 
     onclick="postBackByObject(event,this);">
    <label for="uploadFile" id="labelId">Choose File</label>
    <input class="upload" type="file" id="uploadFile" />
                    </div>
    
    0 讨论(0)
提交回复
热议问题