激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - ASP.NET教程 - 總結(jié)ASP.NET C#中經(jīng)常用到的13個(gè)JS腳本代碼

總結(jié)ASP.NET C#中經(jīng)常用到的13個(gè)JS腳本代碼

2020-01-04 14:12freeliver54 ASP.NET教程

本文總結(jié)了ASP.NET C#在實(shí)際開(kāi)發(fā)過(guò)程中13個(gè)JS腳本代碼,方便大家在開(kāi)發(fā)中使用,希望對(duì)大家有用。

在C#開(kāi)發(fā)過(guò)程中,免不了寫(xiě)一些JS,其實(shí)做后端開(kāi)發(fā)的,本身不擅長(zhǎng)寫(xiě)JS,干脆總結(jié)一下,方便自己也方便別人,分享給大家。呵呵~~

1.按鈕前后臺(tái)事件

 

復(fù)制代碼代碼如下:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"
OnClientClick="alert('客房端驗(yàn)證,阻止向服務(wù)器端提交');return false;" />

 

2.注冊(cè)相關(guān)事件:onblur,onclick,onchange

 

復(fù)制代碼代碼如下:

this.TextBox1.Attributes.Add("onchange",
"alert('數(shù)據(jù)被改動(dòng),現(xiàn)檢查輸入是否符合規(guī)則');");

 

3.注冊(cè)相關(guān)屬性:

 

復(fù)制代碼代碼如下:

this.TextBox1.Attributes.Add("readOnly", "true");

 

4.引入JS文件

前臺(tái)HTML頁(yè)面:

復(fù)制代碼代碼如下:

<script type="text/javascript" src="JScript.js" language="javascript"></script>
<script type="text/javascript" language="javascript">
function fn_Name()
{
    alert("JS");
}
</script>

 

后臺(tái)cs頁(yè)面:

 

復(fù)制代碼代碼如下:


this.RegisterClientScriptBlock("jsFile",
"<script type='text/javascript' src='JScript.js' language='javascript'></script>");
[code]

 

5.點(diǎn)擊按鈕時(shí) 相關(guān)欄位 非空判斷

[code]
function checkEmpty(txtObj,msgShow)
{
    if(txtObj.value == "")
    {
        alert(msgShow);
        return false;
    }
}
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"
OnClientClick="return checkEmpty(TextBox1,'TextBox1 不能為空')" />

 

6.通過(guò)ChcekBox的是否點(diǎn)選來(lái)控制其相對(duì)應(yīng)的TextBox 是否可輸入

 

復(fù)制代碼代碼如下:

function chkTextBox(chkObj,txtObj)
{
    if(chkObj.checked==true)
    {
        txtObj.value = "";
        txtObj.readOnly = false;    
        txtObj.focus();
    }
    if(chkObj.checked == false)
    {
        txtObj.value = "";
        txtObj.readOnly = true;     
    }
}
<input id="Checkbox1" type="checkbox" onclick="chkTextBox(Checkbox1,TextBox1)" />

 

7.傳值到模態(tài)窗口 并得到傳回的值

 

復(fù)制代碼代碼如下:

var EnCodeQueryName = escape(Name);
var strPara = "'dialogWidth: 400px;dialogHeight: 400px;dialogLeft: 300px;dialogTop: 200px;toolbar: no;menubar: no;resizable: yes;location: no;status: no;scrollbars= no'";
var ReturnInfo = window.showModalDialog("QryName.aspx?&Name="+EnCodeQueryName +"&QueryID="+QueryType+"",'',strPara);
if(ReturnInfo !=null)
{
    var arrayReturnInfo = ReturnInfo .split("@");
    document.all.drpID.value = arrayReturnInfo[1];
    document.all.txtName.value= arrayReturnInfo[2];
}

 

8.彈出JS的確認(rèn)對(duì)話框,并根據(jù)確認(rèn)結(jié)果 觸發(fā)后臺(tái)相關(guān)操作

 

復(fù)制代碼代碼如下:

if(confirm('確認(rèn)如何嗎?'))
{
  document.all.hidbtn_Submit.click();
}
else
{
  document.all.hidbtn_Cancel.click();
}

 

HTML頁(yè)面相關(guān)代碼:

 

復(fù)制代碼代碼如下:

<input id="hidbtn_Submit" type="button" value="確認(rèn)修改"
style="display:none;"
onserverclick="hidbtn_Submit_ServerClick"
runat="server" />

 

9.添加頁(yè)面對(duì)快捷鍵的響應(yīng),如 按F2時(shí) 進(jìn)行新增按鈕的操作等

 

復(fù)制代碼代碼如下:

#region 添加頁(yè)面對(duì)快捷鍵的響應(yīng)
string strJS_ShortKey = "<script language='javascript' type='text/javascript' > ";
strJS_ShortKey += " document.onkeydown=shortKeyDown; ";
strJS_ShortKey += " function shortKeyDown()  ";
strJS_ShortKey += " { ";
// 新增
if (this.ButtonCtl1.ImgBtn_AddFamily.Visible)
{
    string btnInsertCID = this.ButtonCtl1.ImgBtn_Insert.ClientID.Trim();
    //F2 - 113
    strJS_ShortKey += " if(event.keyCode=='113') ";
    strJS_ShortKey += "  { ";
    strJS_ShortKey += "    document.all('" + btnInsertCID + "').click();";
    strJS_ShortKey += "    event.keyCode= 0; ";
    strJS_ShortKey += "    event.returnValue = false; ";
    strJS_ShortKey += "    return false; ";
    strJS_ShortKey += "  } ";
}
// 修改
if (this.ButtonCtl1.ImgBtn_Edit.Visible)
{
    string btnEditCID = this.ButtonCtl1.ImgBtn_Edit.ClientID.Trim();
    //F3 - 114
    strJS_ShortKey += " if(event.keyCode=='114') ";
    strJS_ShortKey += "  { ";
    strJS_ShortKey += "    document.all('" + btnEditCID + "').click();";
    strJS_ShortKey += "    event.keyCode= 0; ";
    strJS_ShortKey += "    event.returnValue = false; ";
    strJS_ShortKey += "    return false; ";
    strJS_ShortKey += "  } ";
}
strJS_ShortKey += " } ";
//注冊(cè)事件
Page.RegisterStartupScript("shortKey", strJS_ShortKey);
#endregion

 

10.彈出的提示 分行顯示

 

復(fù)制代碼代碼如下:

alert('aaa \r\n bbb \r\n ccc');


如果是在后臺(tái).cs文件中注冊(cè)
則需要

復(fù)制代碼代碼如下:

string strAlertContent = "aaa"+" \\r\\n ";
strAlertContent += "bbb" +" \\r\\n ";

 

11.點(diǎn)擊GridView上的某一行時(shí),行首列處的RadioButton處于選中狀態(tài),同時(shí)保存相關(guān)值在隱藏欄位

 

復(fù)制代碼代碼如下:

//用查詢(xún)得的數(shù)據(jù)集進(jìn)行綁定
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";   
        }
        //取得對(duì)應(yīng)的Radio對(duì)象
        var tmpRadio = document.getElementById(tmpName);
        //當(dāng)前選中 其他取消選中
        if((i-2) == rowIndex)
        {                 
            tmpRadio.checked = true;
        }
        else
        {
            tmpRadio.checked = false;
        }
    }
    document.all.txthid_GUID.value = rowGUID;
}

 

12.去掉前后空格

 

復(fù)制代碼代碼如下:

function fn_Trim(obj)
{
    if(obj==null)
    {
       return;
    }
    else
    {
        var oldStr = obj.value;
        var newStr = oldStr.replace(/^\s+|\s+$/g,"");
        obj.value = newStr;
    }      
}

 

13.TextBox文本內(nèi)容長(zhǎng)度判斷 看是否超過(guò)長(zhǎng)度 超過(guò)返回true

 

復(fù)制代碼代碼如下:

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;
        }
    }      
}

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 中文字幕在线观看91 | 免费在线观看国产精品 | 色综合久久久久久久久久 | www69xxxxx | av成人免费在线观看 | 国产色视频在线观看免费 | 91成人久久 | 国产成人综合在线 | 国产乱乱视频 | 一级黄色国产视频 | 激情亚洲一区二区 | 国内毛片视频 | 国产一区成人 | 国产午夜精品一区二区三区视频 | 成人三级电影在线 | 一二区电影 | 欧美成人精品欧美一级乱黄 | 二区三区四区视频 | 国产精品一区免费在线观看 | 性视频久久 | 天堂成人一区二区三区 | 毛片毛片免费看 | 亚州视频在线 | 中文字幕综合在线观看 | 免费国产自久久久久三四区久久 | 蜜桃视频在线播放 | 国产三级午夜理伦三级 | mmmwww| 久草亚洲视频 | 国产又粗又爽又深的免费视频 | 国产交换3p国产精品 | 久久综合九色综合久久久精品综合 | 精品国产一区二区三区成人影院 | 免费在线观看成年人视频 | 免费国产自久久久久三四区久久 | 国产小视频一区 | 日韩免费黄色 | 久久精品美乳 | 日本大片在线播放 | 国产一级桃视频播放 | 把娇妻调教成暴露狂 |