Javascript无法在Chrome中运行 [英] Javascript not working in Chrome

查看:501
本文介绍了Javascript无法在Chrome中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我为什么这个简单的javascript无法在Google Chrome中运行吗?



Can anybody tell me why this simple javascript not working in google chrome?

<script type="text/javascript" language="javascript">
function getRdoValue()
{
    if(document.getElementById("rdo_yes").checked)
    {
          document.getElementById("dlst_type").disabled=false;
          document.getElementById("dlst_course_wocktube").disabled=false;
    }
    if(document.getElementById("rdo_no").checked)
    {
        document.getElementById("dlst_type").disabled=true;
        document.getElementById("dlst_course_wocktube").disabled=true;
    }
}
</script>





ASP.NET表单:





ASP.NET Form:

<asp:RadioButton ID="rdo_yes" runat="server" Text="Yes" GroupName="rdo1" onChange="getRdoValue();" />
       <asp:RadioButton ID="rdo_no" runat="server" 

Checked="True" Text="No" GroupName="rdo1" onChange="getRdoValue();" />







<asp:DropDownList ID="dlst_type" runat="server" Enabled="false" AutoPostBack="True" OnSelectedIndexChanged="dlst_type_SelectedIndexChanged">
        </asp:DropDownList>




<asp:DropDownList ID="dlst_course_wocktube" runat="server" Enabled="false">
        </asp:DropDownList>

推荐答案

在编写javascript时,每个asp.net开发人员都会犯下经典错误。你需要使用asp.net控件的客户端ID。您正在使用javascript中的服务器ID。它不适用于Chrome以及任何其他浏览器。



使用此语法



You are making the classical mistake every asp.net developer makes for the first time while writing the javascript .You need to use client ID of the asp.net control. You are using the server id in the javascript. It will NOT work in Chrome as well as any other browser.

Use this syntax

var b = document.getElementById('<%=Button1.ClientID%>');


这篇关于Javascript无法在Chrome中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆