<ItemTemplate>
<asp:TextBox ID="txtReviewM" OnChange="javascript:HandlerCodeTextChange(this);
Text='<%# Bind("ch_slcode") %>' runat="server" Width="100%" Columns="50"
AutoPostBack="true"> </asp:TextBox>
<asp:HiddenField ID="hidempCode" runat="server" />
<asp:HiddenField ID="hidempName" runat="server" />
<ajaxtoolkit:autocompleteextender id="aceHandler2" runat="server"
targetcontrolid="txtReviewM" usecontextkey="true" completionsetcount="10"
completioninterval="500" enablecaching="false" minimumprefixlength="1"
servicemethod="GetEmployee" firstrowselected="true"
completionlistcssclass="AutoExtender"
completionlistitemcssclass="AutoExtenderList"
completionlisthighlighteditemcssclass="AutoExtenderHighlight">
</ajaxtoolkit:autocompleteextender>
</ItemTemplate>
这是我的Javascript功能
function HandlerCodeTextChange(txtBox) {
if (txtBox.value.indexOf(':') == "-1") {
txtBox.value = "";
txtBox.focus();
document.getElementById('<%=hidempCode.ClientID%>').value = "";
document.getElementById('<%=hidempName.ClientID%>').value = "";
}
else {
var code = txtBox.value.split(':');
document.getElementById('<%=hidempCode.ClientID%>').value = code[0];
document.getElementById('<%=hidempName.ClientID%>').value = code[1];
}
}
隐藏字段无法在javascript中找到,我该如何实现呢?
答案 0 :(得分:0)
使用span标记的魔力。它具有这个令人垂涎的功能,当ASP.Net呈现页面时,它的id不会被破坏。使用像这样的span标记来隐藏你的隐藏字段
<ItemTemplate>
<span id='SpanHid'>
<asp:HiddenField ID="hidempCode" runat="server" />
</span>
</ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetHidden();" />
Barebones JavaScript
<script type="text/javascript">
function GetHidden()
{
var elm = document.getElementById("SpanHid");
if (elm!==null)
{
var hiddenfield = elm.children[0].id;
//do stuff with it
}
}
</script>
如果您考虑Jquery,那么您会喜欢这个衬垫
<script type="text/javascript">
function GetHidden()
{
var hiddenfield=$('#SpanHid >input');
//then do stuff with it
}
</script>
你如何调用GetHidden()取决于你的逻辑。