Javascript函数行为 [英] Javascript function behaviour
问题描述
我遇到了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"> Nuovo Coefficiente Energia</asp:ListItem>
<asp:ListItem Value="G"> 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屋!