请问一下,这个代码,写的是不是没有C#代码的风格? protected void btn_cancel_Click(object sender, EventArgs e) { this.txt_username.Text = ""; this.txt_pass.Text = ""; }txt_usernametxt_pass这二个是文本框控件。代码的功能是把文本框内容,清空的功能。请问一下,上面的这个代码,写的是不是没有C#代码的风格?这个代码该怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 C#就这风格了 lz说的是变量命名规范吧 你这啥风格都没 我要是有50个表单 你咋办? 而且 还有下拉框的选项也要重置到 "请选择"什么textAre radiobutton 就不说了 function clearalltext() { document.getElementById("txt_username").value =""; document.getElementById("txt_pwd").value =""; } protected void btn_cancel_Click(object sender, EventArgs e) { txtusername.Text = ""; txtpass.Text = "";或者 tbxusername.Text = ""; tbxpass.Text = ""; } this.txt_username.Text = this.txt_pass.Text = string.Empty; 表单少的话 就一个一个写吧.上了10个的话 还是写个通用的JS方法吧.毕竟重置这种东西 到后台做 体验度太差.JS的写法的话 具体就是遍历 input 然后判断input类型 再来进行不同的重置操作 foreach (Control c in this.form1.Controls) { if (c is TextBox) { (c as TextBox).Text = string.Empty; } } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript" language="javascript" src="jquery-1.3.2.js"></script><script>$( function() { $("#clear").click(function(){ //重置TextBox $(":input").each( function() { if($(this).attr("type")=="text") {$(this).val('');} } ); //重置下拉框 $("select").each( function() { $(this).val('0'); } ); }); } );</script></head><body><form><input type="text" id="a1" /><input type="text" id="a2" /><input type="text" id="a3" /><select><option value="0">--请选择--</option><option value="1">123</option><option value="2">321</option></select><select><option value="0">--请选择--</option><option value="1">123</option><option value="2">321</option></select><input type="button" id="clear" value="重置"/></form></body></html>Jquery 写的 需要下个Jquery的库 网上直接搜下 然后把头部的Src改下 js或者用html控件就能搞定的东西,没必要这样写 这倒是典型c#风格了,尤其是玩asp.net的C# style大多数玩其他语言的都基本不会把 “重置”这个功能非要放到后端代码里去做,因为他们都知道html的input类型实际就一个reset类型是专门做这玩意滴<input type="reset" value="重置" /> asp.net中页面无操作,自动退出! 类型转换错误! 对Cookies进行操作-大伙帮我看看着个问题 如何在javascript里直接调用服务里的方法 VS.net和Dreamweaver结合的问题 在Repeater控件中使用if语句(参考) 如何判断指定表在数据库中是否存在? fileupload控件问题 XML绑定TreeView问题,急!!! 一个关于IIS安装的问题 关于弹出页面传值的问题?很简单的一个小问题 显示文章和动态回复问题
lz说的是变量命名规范吧
我要是有50个表单 你咋办?
而且 还有下拉框的选项也要重置到 "请选择"
什么textAre radiobutton 就不说了
function clearalltext()
{
document.getElementById("txt_username").value ="";
document.getElementById("txt_pwd").value ="";
}
{
txtusername.Text = "";
txtpass.Text = "";
或者
tbxusername.Text = "";
tbxpass.Text = "";
}
上了10个的话
还是写个通用的JS方法吧.
毕竟重置这种东西 到后台做 体验度太差.JS的写法的话
具体就是遍历 input 然后判断input类型 再来进行不同的重置操作
{
if (c is TextBox)
{
(c as TextBox).Text = string.Empty;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" language="javascript" src="jquery-1.3.2.js"></script>
<script>
$(
function()
{
$("#clear").click(function(){
//重置TextBox
$(":input").each(
function()
{
if($(this).attr("type")=="text")
{$(this).val('');}
}
);
//重置下拉框
$("select").each(
function()
{
$(this).val('0');
}
);
});
}
);
</script>
</head><body>
<form>
<input type="text" id="a1" />
<input type="text" id="a2" />
<input type="text" id="a3" />
<select>
<option value="0">--请选择--</option>
<option value="1">123</option>
<option value="2">321</option>
</select>
<select>
<option value="0">--请选择--</option>
<option value="1">123</option>
<option value="2">321</option>
</select>
<input type="button" id="clear" value="重置"/>
</form>
</body>
</html>Jquery 写的 需要下个Jquery的库 网上直接搜下 然后把头部的Src改下