Javascript功能不起作用 [英] Javascript Function Not working

查看:133
本文介绍了Javascript功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写javascript函数

i write javascript function

function Shape()
{
    var lbl1=document.getElementById("<%= Label3.ClientID%>");   
    var ddshap=document.getElementById("<%= ddshpe.ClientID%>");
    if(ddshap.value=='Rectangular')
    { 
       lbl1.innerHTML='Length of sample in cm';
       document.getElementById("rectangular").style.display = '';
    }
    else
    {
       lbl1.innerHTML='Diameter of sample in cm';
       document.getElementById("rectangular").style.display = 'none';
    }
}



并将其设置为dropdowanlist


and set it to dropdowanlist

<asp:DropDownList ID="ddshpe" runat="server" Height="22px" onchange="Shape();" 
CssClass="Textbox">
<asp:ListItem>Rectangular</asp:ListItem>
<asp:ListItem>Cylindrical</asp:ListItem>
</asp:DropDownList>



它在浏览和dropdowan迭代更改后工作正常但是当我从代码中选择iteam时它不能正常工作


it work fine after browse and dropdowan iteam change but when i select iteam from code its not working

protected void Page_Load(object sender, EventArgs e)
{
   ddshpe.Items.FindByText("Cylindrical").Selected = true;
}





制表更正



tabulation corrected

推荐答案

选择服务器端的默认值不会影响客户端。在客户端切换回选择,您将看到JavaScript代码很好...

您必须将显示与原始选择同步,为此添加一行以隐藏'矩形'在Page_Load方法中...

不要使用'rectangle'.Visible = false,这将阻止呈现'矩形'......
Selecting the default value on the server side will not affect the client side. Switch forth back the selection at the client and you will see that the JavaScript code is just fine...
You have to synchronize your display with your original selection, for that add a line to hide 'rectangular' in the Page_Load method...
Do NOT use 'rectangular'.Visible = false, that will prevent the rendering of 'rectangular'...


将'=='替换为'='。你的'=='会抛出解释器的异常,它在浏览器中传播和静默处理,不允许解释下一行。在调试器下运行您的Javascript代码,检查 id 值。您还可以通过查看查看页面源(或类似内容)在浏览器中查看生成的HTML和Javascript代码,特别是比较 id 中的值脚本和HTML。



-SA
Replace '==' with '='. Your '==' would throw interpreter's exception which propagates and id silently handled in the browser, not allowing to interpret next line. Run your Javascript code under the debugger, check up id values. You can also view the resulting HTML and Javascript code in browser, by looking at "View Page Source" (or something like that), and, in particular, compare id values in script and HTML.

—SA


这篇关于Javascript功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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