【发布时间】:2012-04-24 02:39:26
【问题描述】:
我正在尝试使用 jquery 为 asp.net 文本框控件使用水印,下面是我拥有的代码,我在我的 textarea 文本框中看到了标题,但是当我关注或单击文本框时,水印不清除。
我从这里得到了脚本。 http://www.ajaxblender.com/howto-add-hints-form-auto-focus-using-javascript.html
<asp:TextBox runat="server" ID="txtNew" class="auto-hint" title="Enter here ..."
TextMode="MultiLine" Rows="7" Width="100%"></asp:TextBox>
<script type="text/javascript">
$(document).ready(function () {
// Focus auto-focus fields
$('.auto-focus:first').focus();
// Initialize auto-hint fields
$('INPUT.auto-hint, TEXTAREA.auto-hint').focus(function () {
if ($(this).val() == $(this).attr('title')) {
$(this).val('');
$(this).removeClass('auto-hint');
}
});
$('INPUT.auto-hint, TEXTAREA.auto-hint').blur(function () {
if ($(this).val() == '' && $(this).attr('title') != '') {
$(this).val($(this).attr('title'));
$(this).addClass('auto-hint');
}
});
$('INPUT.auto-hint, TEXTAREA.auto-hint').each(function () {
if ($(this).attr('title') == '') { return; }
if ($(this).val() == '') { $(this).val($(this).attr('title')); }
else { $(this).removeClass('auto-hint'); }
});
});
</script>
【问题讨论】:
-
我无法立即看到可能出了什么问题。如果您可以获得一些脚本调试信息,它可能会有所帮助...
-
如果您尝试使用 asp.net 文本框控件,您将看到该行为
-
我刚刚在 ASP.NET 中运行了代码,它按预期工作(输入时水印清除)......我只能建议您使用浏览器调试工具(跟踪和观察)来计算出什么事了。
标签: javascript jquery asp.net