调用“”上的jquery函数;onSelectedIndexChanged”;
Call jquery function on "onSelectedIndexChanged"
我有两个下拉列表和一个文本框。我想显示两个下拉列表中选定值的乘积。
因此,我尝试在"OnSelectedIndexChanged"上调用jquery函数,即使是下拉菜单。然而,我在Visual studio中的构建过程中遇到了错误。
我的代码是:
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px" OnSelectedIndexChanged="javascript:calculateRiskFactor();">
错误为:Invalid expression term ':' and
Invalid expression term ')' and some more
语法有什么问题吗?或者这是调用函数的错误方式?
整个页面的代码是这样的:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Submit_Risks.aspx.cs" Inherits="Risks_Submit_Risks" MasterPageFile="~/MasterPages/SAPMaster.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../Scripts/Validation.js"> </script>
<div class="container">
<div class="contain">
<div class="title">
Risks</div>
<div class="data">
<asp:Label runat="server" ID="lblMsg"></asp:Label>
<table class="style1" align="center">
<tr>
<td class="style2">
Probability (P)
</td>
<td class="style3">
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvProbability" runat="server" ControlToValidate="ddlProbability"
InitialValue="0" ValidationGroup="vgSubmit" ErrorMessage="Probability" ForeColor="Red"
Text="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
Impact (S)
</td>
<td class="style3">
<asp:DropDownList ID="ddlImpact" runat="server" Width="125px">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvImpact" runat="server" ControlToValidate="ddlImpact"
InitialValue="0" ValidationGroup="vgSubmit" ErrorMessage="Impact" ForeColor="Red"
Text="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
</div>
</div>
</div>
据我记忆所及,在ASP.NET WebForms中,OnSelectedIndexChanged
只指向.NET服务器端函数,ASP.NET通过回发调用该函数(如果我错了,请纠正我)。
要将客户端代码绑定到控件(就像使用jQuery一样),为什么不使用jQuery为您做这件事呢?
$('select[id$="ddlProbability"]').change(calculateRiskFactor);
试试这种方法。
<asp:DropDownList ID="ddlProbability" runat="server" Width="125px" OnSelectedIndexChanged="calculateRiskFactor()">
您必须注册DroDownlist的客户端'onchange'
事件。。可以使用注册onchange
事件
DropDownList1.Attributes.Add("onChange", "return OnSelectedIndexChange();")
OnSelectedIndexChange()
是一个javascript函数,当DropDownListBox选择的索引发生更改时,它将在客户端调用。
相关文章:
- 没有找到相关文章