を使用しないインタラクティブなWebフォームで作業しているUpdatePanel
ので、JavaScriptを使用してほとんどの機能を実行しようとしています。この質問では、Javaスクリプトを取得してPageLoad()のドロップダウンリストに関数を追加する方法を理解しようとしています。
私は次のASPファイルを持っています:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Default.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
Discovery Form Templates
<asp:DropDownList ID="uiFormTemplates" runat="server" DataTextField="Subject" DataValueField="DiscoveryFormID" AppendDataBoundItems="true" OnChange="GetTemplateValue();">
<asp:ListItem Text="--Select One--" Value=""/>
</asp:DropDownList>
</div>
<div id="ChangePlate"></div>
</form>
</body>
</html>
そして、このjavascript:
function GetTemplateValue()
{
var dropdown = document.getElementById("uiFormTemplates");
var SelectedOption = dropdown.options[dropdown.selectedIndex].value;
if (SelectedOption == null) {
document.getElementById("ChangePlate").innerText = "There is nothing here.";
}
else {
document.getElementById("ChangePlate").innerText = dropdown;
}
}
私は次のJavaScriptを使おうとしています:
$(document).ready(function () {
$("#uiFormTemplates").onchange(function () { GetTemplateValue(); });
});
OnChange="GetTemplateValue()"
から削除するdropdownlist
と、2番目のjavascriptメソッドを使用しても何も起こりません。私は自分のコードを間違って書いたのですか、それとも私はこれに正しい角度からアプローチしていませんか?コード批評か何らかの方向性のどちらかが今すぐ役立つでしょう、私はjsnoobです。