如何清除页面中以文本形式显示的验证消息. [英] How do i clear the validation message displayed as text in the page.
本文介绍了如何清除页面中以文本形式显示的验证消息.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何清除页面上以文本形式显示的验证消息.代码如下:
How do I clear the validation message displayed as text in the page. Code is given below:
function resettextbox()
{
document.getElementById("spnFirstName").innerHTML=null;
document.getElementById("spnSecondName").innerHTML=null;
document.getElementById("frm1").reset();
}
<html>
<body>
<script type="text/javascript" src="External.js">
</script>
<form id="frm1" method="get">
<table>
<tr>
<td>First Name: <input type="textbox" id="FirstName"/></td>
<td>Second Name:<input type="textbox" id="SecondName"/></td>
<td><input type="button" value="Submit" onClick="return validation()"/></td>
<td><input type="button" value="Reset" onClick="reset()"/></td>
</tr>
<tr>
<td><span id="spnFirstName" span style=color:red></span></td>
<td><span id="spnSecondName" span style=color:red></span></td>
</tr>
</table>
</form>
</body>
</html>
推荐答案
看看这篇文章:
多个字段验证器-一个ASP.NET验证控件 [
Take a look at this article:
Multiple Fields Validator - An ASP.NET Validation Control[^]
It''s probably one of the easier solutions your problem, and the implementation is fairly robust.
Regards
Espen Harlinn
如果您只想清除跨度的内容,请使用以下代码:
If you just want to clear the contents of the span, use this code:
document.getElementById("spnFirstName").innerHTML = '''';
如果要隐藏跨度,请使用以下代码:
If you want to hide the span, use the following code:
document.getElementById("spnFirstName").style.display = '''';
我正在添加代码以进行一些演示:
使用以下Java脚本:
I am adding code to show some demonstration:
Use the following Java Script:
function resettextbox(val) {
document.getElementById("spnFirstName").innerHTML = val;
document.getElementById("spnSecondName").innerHTML = val;
}
function showhidetextbox(val) {
document.getElementById("spnFirstName").style.display = val;
document.getElementById("spnSecondName").style.display = val;
}
使用以下aspx代码:
Use the following aspx code:
<div>
<input type="button" value="HIDE" onclick="showhidetextbox('none');" />
<input type="button" value="Show" onclick="showhidetextbox('');" />
<input type="button" value="Clear" onclick="resettextbox('');" />
<input type="button" value="Set" onclick="resettextbox('Value');" />
<span id="spnFirstName" style="color: red">1</span>
<span id="spnSecondName" style="color: red">2</span>
</div>
这篇关于如何清除页面中以文本形式显示的验证消息.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文