源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

总结ASP.NET C#中经常用到的13个JS脚本代码

  • 时间:2022-09-16 01:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:总结ASP.NET C#中经常用到的13个JS脚本代码
在C#开发过程中,免不了写一些JS,其实做后端开发的,本身不擅长写JS,干脆总结一下,方便自己也方便别人,分享给大家。呵呵~~ [b]1.按钮前后台事件[/b]
[url=file://\\r\\n]\\r\\n[/url] "; strAlertContent += "bbb" +" [url=file://\\r\\n]\\r\\n[/url] ";
[b]11.点击GridView上的某一行时,行首列处的RadioButton处于选中状态,同时保存相关值在隐藏栏位[/b]
[u]复制代码[/u] 代码如下:
//用查询得的数据集进行绑定 if (dt.Rows.Count > 0) {     //绑定     this.gv_InfoFromSendModule.DataSource = dt;     this.gv_InfoFromSendModule.DataBind();     //确定按钮显示     this.btn_OK.Visible = true;     this.txthid_RowCount.Text = dt.Rows.Count.ToString(); } //GridView的RowDataBound protected void gv_InfoFromSendModule_RowDataBound(object sender, GridViewRowEventArgs e) {    if (e.Row.RowIndex < 0)       return;    e.Row.Attributes.Add("onclick", "radButton('" + e.Row.RowIndex.ToString() + "','" + e.Row.Cells[1].Text.Trim() + "');");    //RadioButton rad = (RadioButton)e.Row.Cells[0].FindControl("rad_Select");    //rad.Attributes.Add("onclick", "radButton('"+e.Row.RowIndex.ToString()+"','"+ e.Row.Cells[1].Text.Trim()+"');"); } //行上所绑定的JS function radButton(rowIndex,rowGUID) {     //gv_InfoFromSendModule$ctl02$rad_Select     var rowCount = parseInt(document.all.txthid_RowCount.value)+2;     for(var i=2;i<rowCount;i++)     {         var tmpName;         if(i<10)         {             tmpName = "gv_InfoFromSendModule$ctl0"+i+"$rad_Select";                       }         else         {             tmpName = "gv_InfoFromSendModule$ctl"+i+"$rad_Select";           }         //取得对应的Radio对象         var tmpRadio = document.getElementById(tmpName);         //当前选中 其他取消选中         if((i-2) == rowIndex)         {                             tmpRadio.checked = true;         }         else         {             tmpRadio.checked = false;         }     }     document.all.txthid_GUID.value = rowGUID; }
[b]12.去掉前后空格[/b]
[u]复制代码[/u] 代码如下:
function fn_Trim(obj) {     if(obj==null)     {        return;     }     else     {         var oldStr = obj.value;         var newStr = oldStr.replace(/^\s+|\s+$/g,"");         obj.value = newStr;     }      }
[b]13.TextBox文本内容长度判断 看是否超过长度 超过返回true[/b]
[u]复制代码[/u] 代码如下:
function fn_IsTooLong(obj,varLength) {     if(obj==null)     {        return false;     }     else     {         var valueStr = obj.value;         var len = valueStr.match(/[^ -~]/g) == null ? valueStr.length : valueStr.length + valueStr.match(/[^ -~]/g).length ;         if(len > parseInt(varLength) )         {             return true;         }         else         {             return false;         }     }      }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部