【发布时间】:2012-09-30 21:19:01
【问题描述】:
我必须在 ASP.net 页面的文本字段中添加默认灰色文本,如下所示:
当用户点击/输入一个字段时,默认文本消失。
如何在文本框事件中执行此操作?
我设法实现了 onFocus 事件来改变文本颜色;在我的 .aspx 页面中,我为 JS 代码创建了一个 <script> 标记:
<script type="text/javascript">
function test(obj) {
obj.style.color = "grey";
}
</script>
后面的代码:
txtBox.Attributes.Add("OnFocus", "test(this)")
'txtBox is the ID of text Box
现在问关于 JavaScript OnFocus 事件的非常基本的问题很尴尬。
但是问题是知识的关键 :)
编辑:我不能在我的 ASP.Net 页面中使用任何 HTML 标记
有什么帮助吗?谢谢。
【问题讨论】:
-
如果您可以使用 jQuery,那么您学习它会容易得多。 api.jquery.com/focusin
-
@udidu 请检查我更新的问题
标签: javascript asp.net vb.net onfocus