我有兩個下拉菜單和一個文本框。 我想顯示兩個下拉列表中所選值的乘法。在「onSelectedIndexChanged」上調用jquery函數
所以我想在「OnSelectedIndexChanged」甚至是下拉菜單上調用jquery函數。 Hoever我在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>
嘗試像這樣OnSelectedIndexChanged =「calculateRiskFactor();」 – 2012-03-15 06:28:01
試着看看[這個](http://www.codeproject.com/Articles/656/Using-JavaScript-to-handle-drop-down-list-selectio) – 2012-03-15 06:27:24