[英]Will this code work? Javascript/asp.net (Code not working)
<td class="style4">
<input type="text" ID="txtFirstName" runat="server" maxlength="50"
class="DefaultTextbox" style="width:180px;" value="First Name"
onfocus="if(this.value=='First Name') {this.value = '';document.getElementById('spanFirstName').visible=false;}"
onblur="if(this.value=='') this.value = 'First Name'"
/>
</td>
<td>
<span id="spanFirstName">Should be less than 50 characters.</span>
</td>
我想做這樣的事情
onfocus = "if(this.value=='First Name')
{
this.value = '';
document.getElementById('spanFirstName').visible=false;
}"
onblur = "if(this.value=='') this.value = 'First Name'"
我不知道asp.net,但在此行查看您的代碼后:
document.getElementById('spanFirstName').visible=false;
我認為可以將其替換為以下行:
document.getElementById('spanFirstName').style.visibility='hidden';
不確定,但這就是我們的操作方式,這可能是問題的原因。
謝謝
我認為您正在尋找TextBoxWatermark 。 這是一個不錯的
對於您的代碼,您可以這樣做
<script type='text/javascript'>
function HideSpan(elem)
{
if ( elem.value == 'First Name' )
{
elem.value = '';
document.getElementById("spanFirstName").style.visibility = 'hidden';
}
}
function SetText(elem)
{
if ( elem.value == '' )
{
elem.value = 'First Name';
document.getElementById("spanFirstName").style.visibility = 'visible';
}
}
</script>
<table>
<tr>
<td class="style4">
<input type="text" ID="txtFirstName" runat="server" maxlength="50"
class="DefaultTextbox" style="width:180px;" value="First Name"
onfocus="HideSpan(this);" onblur="SetText(this);"
/>
</td>
<td>
<span id="spanFirstName">Should be less than 50 characters.</span>
</td>
</tr>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.