C#如何清空多个textbox中的文本?

C#如何清空多个textbox中的文本?,第1张

遍历窗体所有的textBox代码:foreach(Control c in thisControls)//遍历所有控件
{
if (c is TextBox)//判断是否是textBox控件,是则清空
{
cText = "";
}
}

可以使用 jQuery 设置内容的val()方法来实现,设置内容为空即达到清空文本框内容的目的:
1

$("input[name='test']")val("")focus(); // 将name=test的文本框清空并获得焦点,以便重新输入
示例代码如下
创建Html元素
<div class="box">
<span>点击按钮后清除文本框内容:</span>
<div class="content">
<input type="text" name="test" value="这是默认的内容">
</div>
<input type="button" class="btn" value="清除文本框内容">
</div>
设置css样式
divbox{width:300px;height:250px;padding:10px 20px;margin:20px;border:4px dashed #ccc;}
divbox>span{color:#999;font-style:italic;}
divcontent{width:250px;height:100px;margin:10px 0;padding:5px 20px;border:2px solid #ff6666;}
input[type='text']{width:200px;height:30px;border:none;}
input[type='button']{width:120px;height:30px;margin:10px;border:2px solid #ebbcbe;}
编写jquery代码

$(function(){
$("input:button")click(function() {
$("input[name='test']")val("")focus(); // 清空并获得焦点
});
})

如果不想手动清除处理内容的话,可以在按下求值按钮时得到一个bool类型的标记,每次输入其他数字时判断该标记是否为“true”,是的话清空显示用的TextBox的Text属性就可以了。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/13344604.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-18
下一篇 2023-07-18

发表评论

登录后才能评论

评论列表(0条)

保存