JavaScript适用于IE,但不适用于Firefox和Chrome

javascript works on IE but doesnt on firefox and chrome

本文关键字:适用于 Firefox Chrome 不适用 IE JavaScript      更新时间:2023-09-26

这段javascript代码只适用于IE,为什么以及如何让它在Firefox和chrome上工作。提前谢谢。

爪哇语

 function uploadFileChange() {
        if (document.getElementById('textbox1').value != document.getElementById("FileUpload1").value) {
            document.getElementById('textbox1').value = document.getElementById("FileUpload1").value;
        }
        return false;
    }

HTML/asp.net

<div class="fileinputs">
    <!-- Upload file invisivel-->
    <asp:FileUpload ID="FileUpload1" ClientIDMode="Static" class="file" runat="server"
        onpropertychange="uploadFileChange();" />
    <!-- button e textbox falsas para poder dar syles ao button-->
    <div class="fakefile">
        <asp:TextBox ID="textbox1" CssClass="textbox" ClientIDMode="Static" runat="server"
            Width="31%" ReadOnly="true" />
        <asp:Button ID="FileChooserButton1" CssClass="btnSubmit" runat="server" Text="Procurar..."
            ForeColor="White" />
        <asp:Button ID="FileChooserButton2" CssClass="btnSubmit" Text="Apagar" ForeColor="White"
            OnClientClick="clear();" runat="server" />
    </div>
</div>

解决

onpropertychange 事件仅是 IE,因此不会在其他浏览器中触发,请参阅 http://help.dottoro.com/ljufknus.php。

改用 onchange 事件 http://forums.asp.net/t/1138684.aspx/1

使用警报。 并尝试提醒两个值..你会知道原因的..很可能是其他浏览器返回未定义...最好使用警报并调试值。它可能会 b 编码错误。