Javascript函数行为 [英] Javascript function behaviour

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

问题描述

我遇到了javascript问题。
在我的代码中有一个单选按钮,点击它应该调用 UcSelect()函数。我尝试了下面的代码,但它没有奏效。
函数只是尝试打印某些内容,以帮助我理解代码的行为。

 < script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js> 

函数UcSelect(){
alert('hello1');
if($(#rbtTipo:checked)。val()=='E'){
alert(aaaaaaaaaaaaa);
}
if($(#rbtTipo:checked)。value =='E'){
alert(bbbbbbbbbbbbbbbbbb);
}
返回true;
}

< / script>

和单选按钮:

 < asp:RadioButtonList ID =rbtTiporunat =serverstyle =margin-top:4px; margin-bottom:8px;的onclick = UcSelect(); > 
< asp:ListItem Value =E>& nbsp; Nuovo Coefficiente Energia< / asp:ListItem>
< asp:ListItem Value =G>& nbsp; Nuovo Coefficiente Gas< / asp:ListItem>
< / asp:RadioButtonList>


解决方案

script 元素可以有一个 src 属性内容,但不能同时包含这两种。如果他们同时拥有这些内容,那么内容将被忽略(内容被视为脚本文档,而不是代码)。

当您使用ASP.NET和 rbtTipo 是您需要使用的服务器控件 Control.ClientID



<%= rbtTipo.ClientID%> 将获取由HTML标记生成的控件ID ASP.NET。

 < script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs /jquery/1.7.0/jquery.min.js\"> 
< / script>
< script>
函数UcSelect(){
var value = $(#<%= rbtTipo.ClientID%>:checked)。val();
if(value =='E'){
alert(aaaaaaaaaaaaa);
}
if(value =='G'){
alert(bbbbbbbbbbbbbbbbbb);
}
返回true;
}
< / script>


I have a problem with javascript. In my code there is a radio button, on click it should call the UcSelect() function. I tried the code below but it didn't work. The function just try to print something in order to help me to understand the behavior of the code.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">   

    function UcSelect() {
        alert('hello1');
        if ($("#rbtTipo :checked").val() == 'E') {
            alert("aaaaaaaaaaaaa");
        }
        if ($("#rbtTipo :checked").value == 'E') {
            alert("bbbbbbbbbbbbbbbbbb");
        }
        return true;
    }

</script>

And the radio button:

<asp:RadioButtonList ID="rbtTipo" runat="server" Style="margin-top: 4px; margin-bottom: 8px;" onclick="UcSelect();" >
        <asp:ListItem Value="E">&nbsp; Nuovo Coefficiente Energia</asp:ListItem>
        <asp:ListItem Value="G">&nbsp; Nuovo Coefficiente Gas</asp:ListItem>
    </asp:RadioButtonList>

解决方案

script elements can have a src attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).

As you are using ASP.NET and rbtTipo is a server control you need to use Control.ClientID.

<%= rbtTipo.ClientID %> will Gets the control ID for HTML markup that is generated by ASP.NET.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
</script>
<script>
    function UcSelect() {
        var value = $("#<%= rbtTipo.ClientID %> :checked").val();
        if (value == 'E') {
            alert("aaaaaaaaaaaaa");
        }
        if (value == 'G') {
            alert("bbbbbbbbbbbbbbbbbb");
        }
        return true;
    }
</script>

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

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