JAVASCRIPT各種指令碼

來源:互聯網
上載者:User

1.如何控制在DataList中的CheckBox選擇不能超過3個
.cs
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
CheckBox cbx=(CheckBox)e.Item.FindControl("CheckBox1");
cbx.Attributes.Add("onclick","checkIt(this)");
}

.aspx 

<script language=javascript>
var num=0;
function checkIt(obj){
  if(obj.checked){
    num++;
  }else{
    num--;
  }
  if(num>3){
    num--;
    obj.checked = false;
    alert("不能超過三個!");
  }
}
</script>

2.datalist中刪除選中行
<ItemTemplate>
              <span style="cursor: hand" id="span<%#((Messaging.DataProvider.MessageRecord) GetDataItem()).ID%>" onclick="DeleteMessge(<%#((Messaging.DataProvider.MessageRecord) GetDataItem()).ID%>,this)">刪除</span> <a href="Reply.aspx?originChatTo=<%#((Messaging.DataProvider.MessageRecord) GetDataItem()).ChatTo%>" style="text-decoration: none; color: #666666;" target="_blank">回複</a>

              <script type="text/javascript" language="javascript">
               function DeleteMessge( theID,thisObj )
               {
                 window.confirm("您確定要刪除該條訊息嗎?");
                 Inbox.DeleteMessage( theID );  //AJAX無重新整理刪除
                 thisObj.parentElement.parentElement.removeNode(true);
               }
              </script>
 </ItemTemplate>
3.當使用者點擊了瀏覽器關閉按鈕按鈕,在瀏覽器沒有關閉之前(能夠看到當前瀏覽器頁面的內容)彈出一個提示,提醒使用者可能有未儲存的資料
function window.onbeforeunload()  
  {  
  if(event.clientX>360&&event.clientY<0||event.altKey)  
  {  
  window.event.returnValue="";  
  }  
  }
4.給刪除按鈕添加了一個彈出對話方塊 屬性,能否根據使用者登陸情況彈出不同的對話方塊:未登陸使用者對話方塊的內容是"沒有許可權",登陸使用者是"是否刪除"!
前台js

function GoCheck(type)
{
    if(type == 0)
    {
         alert("沒有許可權");return false;
    }
    else return confirm("是否刪除!");
}
後台.cs
int i;
        if (sUid == "" || sUid == null || sUid != uid) { i = 0; }
        else{i=1;}
        btn_del.Attributes.Add("onclick", "return GoCheck_del(" + i.ToString() + ");");
        btn_modify.Attributes.Add("onclick", "return GoCheck_mod(" + i.ToString() + ");");

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.