【发布时间】:2015-04-27 21:28:38
【问题描述】:
我一直在搜索互联网和 stackoverflow,但还没有找到可行的解决方案。当 onfocus 发生时,我需要从文本框中删除默认文本。我知道它正在聚焦,因为我的文本颜色类也设置在那里并且颜色正在改变。这是我的代码和我尝试过的。
平均售价:
<asp:TextBox ID="txtAddEditDel" runat="server" CssClass="txtAddEditDel" ></asp:TextBox>
默认文本是在 Page_Load 上填充的一些随机指令。
jquery:
$(".txtAddEditDel").focus(function () {
var selectedRoleText = $(this).find('option:selected').text();
var selectedRoleId = $(this).find('option:selected').val();
var selectedRoleIndex = $(this).find('option:selected').index();
//enable add button
enableDisableLinkButtons(true, true, true);
if (selectedRoleText == 'Create, Edit, or Delete a Role Name.') {
$(".txtAddEditDel:text").val('');
}
$(".txtAddEditDel").removeClass('placeholderText');
});
removeClass 函数被命中,但我的值没有被清除。 这是我尝试过的:
$(".txtAddEditDel").val('');
$(".txtAddEditDel").val("");
$(".txtAddEditDel").text("");
$(".txtAddEditDel").text == '';
$(".txtAddEditDel").text == "";
$(this).val('');
document.getElementbyId('<%= txtAddEditDel.ClientID %'>.value = "";
【问题讨论】:
-
为什么不使用占位符属性作为默认文本?它将被自动删除。 IE。 jsfiddle.net/qdthqkj1
标签: javascript c# jquery asp.net web-controls