0
摘要: 我试图设置一条错误消息,如果没有通过下拉菜单进行选择。在javascript中设置标签的文本
详情:
这里是我的DD有一个JavaScript函数的调用:
<%:Html.DropDownListFor(r => Model.TypeId, TypeItems, new { @class="stretchInput", @onblur = "errorCheck"})%>
这里是我的javascript:
<script type="text/javascript">
$(document).on("blur", "select[name=TypeId]",
function errorCheck() {
var errId = 'Type not chosen. Please choose from the menu.';
if (document.getElementById('TypeId').selectedIndex == 0) {
document.getElementById("DetailsError").visibility = 'visible';
document.getElementById("DetailsError").innerHTML = errId;
}
});
</script>
下面是我想改变的值的标签:
<td><asp:Label ID="DetailsError" runat="server" CssClass="errorMsg" Text="testing" Visible="false"></asp:Label></td>
我知道这是一个ASP控制,顺便说一句。我试过HTML label
并得到相同的结果。
我试图用我的错误信息设置标签的文本。看起来我没有做任何事情影响标签。
我错过了什么?
查看生成的页面源,查找标签。你看到了什么? – epascarello
testing – user2284341
BINGO!我以“MainContent_”为前缀DetailsError,它起作用。谢谢epascarello! – user2284341