如何在textarea中设置null值 [英] How to set null value in textarea
本文介绍了如何在textarea中设置null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在textarea的onclick()事件中设置null值,但我的代码无法正常工作..
< textarea id = txtwishlistsong1 行 = 5 cols = 70 runat = server önclick = 返回txtwishlistsong1_onclick() > 类型您的留言... < / textarea >
代码落后:
function txtwishlistsong1_onclick()
{
document .getElementById(' txtwishlistsong1')。focus();
document .getElementById(' txtwishlistsong1').value= null ;
}
解决方案
我认为问题在于textarea控件的ID,你的控件被标记为runat =server
所以它的ID将被更改,因此您应该使用它的ClientID
属性来访问它。 / blockquote>
我想在客户端使用它然后使用
< textarea id =txtwishlistsong1 rows =5cols =70runat =serverönClientclick=return txtwishlistsong1_onclick()>在此输入您的留言...< / textarea>
和你的功能。
如果你想在代码隐藏中使用它然后添加
txtwishlistsong1.text = string.Empty;
我假设您正在尝试在textarea中写一个水印,当点击它时你想要水印文字消失。它可以使用简单的javascript或jquery或AJAX扩展器完成
看看以下链接,希望他们能帮到你:
使用jQuery:
Display-Watermark-Text-for-ASPNet-MultiLine-TextArea-using-jQuery-Plugin.aspx [ ^ ]
使用Javascript:
如何创建水印文本框使用javascript [ ^ ]
使用AJAX Extender:
WaterMark Extender [ ^ ]
检查CP的链接:
如何在asp.net for Textbox中使用水印 [ ^ 一>
I want to set null value in onclick() event of textarea, But my code does not work properly..
<textarea id="txtwishlistsong1" rows="5" cols="70" runat="server" önclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea>
code behind:
function txtwishlistsong1_onclick() { document.getElementById('txtwishlistsong1').focus(); document.getElementById('txtwishlistsong1').value=null; }解决方案I think problem is in ID of textarea control, your control is marked asrunat="server"
so its ID will be changed so you should useClientID
property of it to access it in javascript.
I you want this it on client side then use
<textarea id="txtwishlistsong1" rows="5" cols="70" runat="server" önClientclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea>
and you function.
If you want this in code-behind then add
txtwishlistsong1.text=string.Empty;
I am assuming you are trying to write a watermark in your textarea and when there is a click on it you want the watermark text to disappear. It can be done using simple javascript or jquery or AJAX extender
Take a look at following links, hope they help you:
Using jQuery:
Display-Watermark-Text-for-ASPNet-MultiLine-TextArea-using-jQuery-Plugin.aspx[^]
Using Javascript:
how-to-create-watermark-textbox-using-javascript[^]
Using AJAX Extender:
WaterMark Extender[^]
Check link from CP as well:
How to use watermark in asp.net for Textbox[^]
这篇关于如何在textarea中设置null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文