C# 如何在文本区域中设置空值
我想在textarea的onclick()事件中设置空值,但我的代码无法正常工作C# 如何在文本区域中设置空值,c#,javascript,asp.net,C#,Javascript,Asp.net,我想在textarea的onclick()事件中设置空值,但我的代码无法正常工作 <textarea id="txtwishlistsong1" rows="5" cols="70" runat="server" onclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea> 原因可能是asp.net ID损坏 尝试使用: document.getElementById('
<textarea id="txtwishlistsong1" rows="5" cols="70" runat="server" onclick="return txtwishlistsong1_onclick()">Type Your Message Here...</textarea>
原因可能是asp.net ID损坏 尝试使用:
document.getElementById('<%=txtwishlistsong1.ClientID%>').focus();
document.getElementById('<%=txtwishlistsong1.ClientID%>').value=null;
document.getElementById(“”).focus();
document.getElementById(“”).value=null;
设置空值:”
(非null
)
据此,值为
DOMString
,并且必须始终具有输入的当前值。由于input
不能真正具有null
值(在本例中它是相当抽象的),因此空值是更好的选择(并且在不同浏览器中一致工作)。将控件定义为runat=“server”
要在JavaScript中访问它们,需要指定ClientID
function txtwishlistsong1_onclick()
{
document.getElementById('<%= txtwishlistsong1.ClientID %>').focus();
document.getElementById('<%= txtwishlistsong1.ClientID %>').value='';
}
函数txtwishlistsong1_onclick()
{
document.getElementById(“”).focus();
document.getElementById(“”).value=“”;
}
或者,如果您使用的是.Net framework 4.0或更高版本,则可以为控件指定ClientIDMode=“Static”
,请参阅更多关于的信息,为什么要将代码放在代码中并尝试调用它?您正在执行客户端操作,因此只需将函数放入
。这段代码中有什么问题?它工作正常。有什么问题吗?.value=null
和.value=”“
之间有什么区别?为什么要这么麻烦?…目标id
是用于调用此函数的元素onclick
。只需将此传递给函数并使用param.focus()代码>和<代码>参数值=”代码>
function txtwishlistsong1_onclick()
{
document.getElementById('<%= txtwishlistsong1.ClientID %>').focus();
document.getElementById('<%= txtwishlistsong1.ClientID %>').value='';
}