最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2016年04月18日 10:41:05   作者:freeliver54  
本文總結(jié)了ASP.NET C#在實(shí)際開發(fā)過程中13個(gè)JS腳本代碼,方便大家在開發(fā)中使用,希望對(duì)大家有用。

在C#開發(fā)過程中,免不了寫一些JS,其實(shí)做后端開發(fā)的,本身不擅長(zhǎng)寫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頁面:

復(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頁面:

復(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.通過ChcekBox的是否點(diǎn)選來控制其相對(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頁面相關(guān)代碼:

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

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

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

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

#region 添加頁面對(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ù)制代碼 代碼如下:

//用查詢得的數(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)度判斷 看是否超過長(zhǎng)度 超過返回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;
        }
    }     
}

相關(guān)文章

  • 利用ascii碼傳輸xml轉(zhuǎn)義字符示例

    利用ascii碼傳輸xml轉(zhuǎn)義字符示例

    這篇文章主要介紹了利用ascii碼傳輸xml轉(zhuǎn)義字符示例,需要的朋友可以參考下
    2014-05-05
  • ASP.NET中實(shí)現(xiàn)定制自己的委托和事件參數(shù)類

    ASP.NET中實(shí)現(xiàn)定制自己的委托和事件參數(shù)類

    這篇文章主要介紹了ASP.NET中實(shí)現(xiàn)定制自己的委托和事件參數(shù)類,需要的朋友可以參考下
    2014-08-08
  • ASP.NET?Core實(shí)現(xiàn)動(dòng)態(tài)獲取文件并下載

    ASP.NET?Core實(shí)現(xiàn)動(dòng)態(tài)獲取文件并下載

    這篇文章介紹了ASP.NET?Core實(shí)現(xiàn)動(dòng)態(tài)獲取文件并下載的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • ASP.NET 獲取存儲(chǔ)過程返回值的實(shí)現(xiàn)代碼

    ASP.NET 獲取存儲(chǔ)過程返回值的實(shí)現(xiàn)代碼

    ASP.NET 獲取存儲(chǔ)過程返回值的實(shí)現(xiàn)代碼,需要的朋友可以參考下。
    2011-12-12
  • asp.net Cookie值中文亂碼問題解決方法

    asp.net Cookie值中文亂碼問題解決方法

    cookie里面不能寫中文,是由于cookie先天的編碼方式造成的,所以有必要存在一種中間的編碼方式:URLEncode是最好的選擇,感興趣的你可千萬不要錯(cuò)過了哈,或許本文提供的知識(shí)點(diǎn)對(duì)你學(xué)習(xí)cookie有所幫助
    2013-02-02
  • 微信開發(fā)(一) asp.net接入

    微信開發(fā)(一) asp.net接入

    我們要進(jìn)行微信公眾平臺(tái)的開發(fā),第一步當(dāng)然是要有公眾號(hào)了。什么?不知道什么是微信公眾號(hào),看來你還要先回爐煉煉了,呵呵。通俗的說,我們微信平臺(tái)就好像是一個(gè)大社會(huì),里面有個(gè)體人,也有各種組織機(jī)構(gòu)。
    2016-05-05
  • asp.net?core?中的Jwt(Json?Web?Token)的使用詳解

    asp.net?core?中的Jwt(Json?Web?Token)的使用詳解

    session不支持分布式并且在服務(wù)器存儲(chǔ)一份用戶登錄的信息,這份登錄信息會(huì)在響應(yīng)時(shí)傳遞給瀏覽器,告訴其保存為cookie,以便下次請(qǐng)求時(shí)發(fā)送給我們的應(yīng)用,這篇文章主要介紹了asp.net?core?中的Jwt(Json?Web?Token)的使用,需要的朋友可以參考下
    2022-10-10
  • ASP.NET使用GridView導(dǎo)出Excel實(shí)現(xiàn)方法

    ASP.NET使用GridView導(dǎo)出Excel實(shí)現(xiàn)方法

    這篇文章主要介紹了ASP.NET使用GridView導(dǎo)出Excel實(shí)現(xiàn)方法,是asp.net操作office文件的一個(gè)典型應(yīng)用,代碼中備有較為詳盡的注釋便于讀者理解,需要的朋友可以參考下
    2014-11-11
  • .NET Core如何獲取操作系統(tǒng)中的各種信息

    .NET Core如何獲取操作系統(tǒng)中的各種信息

    .net core是最近討論頻率很高的話題,下面這篇文章主要給大家介紹了關(guān)于利用.NET Core如何獲取操作系統(tǒng)中各種信息的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧
    2018-05-05
  • asp.net Web Services上傳和下載文件(完整代碼)

    asp.net Web Services上傳和下載文件(完整代碼)

    隨著Internet技術(shù)的發(fā)展和跨平臺(tái)需求的日益增加,Web Services的應(yīng)用越來越廣,我們不但需要通過Web Services傳遞字符串信息,而且需要傳遞二進(jìn)制文件信息。
    2008-12-12

最新評(píng)論

洛隆县| 明星| 兰溪市| 周至县| 桦川县| 孟州市| 阿鲁科尔沁旗| 荔浦县| 天镇县| 始兴县| 中卫市| 阿克陶县| 陈巴尔虎旗| 临清市| 烟台市| 赤水市| 伽师县| 汉寿县| 玛多县| 长治市| 武乡县| 梓潼县| 磴口县| 南安市| 潜江市| 葵青区| 丰原市| 安阳县| 句容市| 公主岭市| 卢氏县| 红河县| 肇州县| 长兴县| 勃利县| 泰顺县| 彭州市| 南昌县| 德惠市| 武义县| 车险|