2014年8月9日 星期六

C# + Jquery 的Ajax換頁

.aspx

 <script src="js/jquery.pagebar_min.js" type="text/javascript"></script>

    <script type="text/javascript">

        //換頁      
        $(function () {
            changPage(1);
        });

         var total = 100;

        function page(idx) {
            var pagebar_arg = {
                firstPageText: "<span class=\"gr12\"> 第一頁</span>", //"第一頁",
                previousPageText: "<span class=\"gr12\"> 上一頁</span>", //"上一頁",
                nextPageText: "<span class=\"gr12\"> 下一頁› </span>", //"下一頁",
                lastPageText: "<span class=\"gr12\"> 最末頁››</span>" //"最末頁"
            };

            $("#pager").fadeIn().showPageBarPlus(total, <%= pageShowNum %>, idx, changPage, pagebar_arg);
        }


        function changPage(idx) {
           
                data = {
                    pageShowNum: <%= pageShowNum %>,
                    nodeId: <%= nodeId %>,
                    index: idx
                };

                $.ajax({
                    async: false,
                    type: 'post',
                    url: 'PageList.ashx',
                    data: data,
                    dataType: 'text',
                    success: function (s1) {    
                        //alert(s1);
                        if(s1.split("<%= sign %>").length >= 2){

                            $("#list").fadeIn().html(s1.split("<%= sign %>")[0]);
                            total = s1.split("<%= sign %>")[1];

                            //$("#totalNum").text(total);
                        }
                 
                    }


                });

                page(idx);
            }



    </script>

<body>
    <div id='list'></div>
    <div id='pager'></div>
</body>




PageList.ashx

    public void ProcessRequest (HttpContext context) {

        int pageShowNum = Int32.Parse(context.Request.Form["pageShowNum"]);
        int index = Int32.Parse(context.Request.Form["index"]);
        //int selectNodeTreeId = Int32.Parse(context.Request.Form["nodeTreeId"]);
        int nodeId = Int32.Parse(context.Request.Form["nodeId"]);

        StringBuilder sb = new StringBuilder();

        DBManger DBManger = new DBManger();
        DataSet ds = DBManger.GetPage(index, pageShowNum, "user");   //取得db資料

        DataTable dt = ds.Tables[1]; //搜出的資料
        int totalPage = (int)ds.Tables[0].Rows[0]["total"];

        sb.Append("<table>");
       
        //加入colume 名稱
        sb.Append("<tr class='White_box'>");
        for (int i = 0; i < dt.Columns.Count; i++)
        {
            sb.Append("<th width=\"6%\">" + dt.Columns[i].ToString() + " </th>");
        }
        sb.Append("</tr>");

        //加入內容
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("<tr class=\"White_box\">");

            for (int j = 0; j < dt.Columns.Count; j++)
            {
                sb.Append("<td>" + dt.Rows[i][j].ToString() + "</td>");
            }
           
            sb.Append("</tr>");
        }
        sb.Append("</table>");


        string htmlStr = "";

        htmlStr = sb.ToString() + sign + totalPage;

        context.Response.ContentType = "text/plain";
        context.Response.Write(htmlStr);
    }

標籤: ,

2014年4月21日 星期一

Multiple Select 元素選取 - Jquery

<script type="text/javascript">

function AddItem() {

        var optionStr = "";

        $("#ExamineItem :selected").each(function () {
            //alert($(this).text());

            //判斷是否有重複選取的物件
            var SelectedExamineItem = $("#SelectedExamineItem");
            var ExamineItem = $(this);
            var check = true;

            $(SelectedExamineItem).find("option").each(function () {

                if ($(ExamineItem).text() == $(this).text()) {
                    check = false;
                }
            });


            if (check) {
                optionStr += "<option value='" + $(this).text() + "'>" + $(this).text() + "</option>";
            }
        });

        if (optionStr != "") {
            $("#SelectedExamineItem").append(optionStr);
        }
    }

    function CanelItem() {

        $("#<%= SelectedExamineItem.ClientID %> :selected").each(function () {
            $(this).remove();
        });
    }

</script>

<body>

<select id="ExamineItem" name="ExamineItem" style=" width:200px; height:100px" multiple>
    </select>

    <input type="button" value=">" onclick="AddItem()" />
    <input type="button" value="<" onclick="CanelItem()" />

    <select id="SelectedExamineItem" name="SelectedExamineItem"  style=" width:200px; height:100px" multiple>                    
    </select>


</body>

標籤:

2014年1月24日 星期五

javascript scrollbar 到網頁底部後執行

var $terms = $(window),
   _height = $terms.height(),
   _scrollHeight = $(document).height(),
   _maxScrollHeight = _scrollHeight - _height - 20;
        var _least = 0; // 距離底部多少就可以, 0 表示得完全到底部

        // 當 #terms 中捲軸捲動時
        $(window).scroll(function () {
            var $this = $(this);
            // 如果高度已經達到指定的高度就啟用 $submit


            if (_maxScrollHeight - $this.scrollTop() <= _least) {
               
                alert("到底了");

            }
           
        });

標籤: ,

2014年1月16日 星期四

Jquery Mobile 捲軸到底 並執行

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>

<script type="text/javascript">

    $(function () {
        $(document).on("scrollstart", function () {

            if ($(window).scrollTop() + $(window).height() == $(document).height()) {
                //捲軸到底後會執行
                $("#content").clone().appendTo($("#content"));

            }
        });

    });
</script>

<body>
    <div id="terms" style='overflow:auto;'>
        <div data-role="page">
            <div data-role="header">
                <h1>silentScroll() example</h1>
            </div>
            <div id="content" role="main" class="ui-content">
                <a href="#" onclick="" data-role="button">Go down 100 pixels</a>
                <p> <br><br>Here, we have some text so that we can have <br>
                some vertical space in order to demonstrate <br>
                the silentScroll() method.<br><br></p>
                <a href="#" onclick="$.mobile.silentScroll(0)" data-role="button">Back to Top</a>
            </div>
            <div data-role="footer">
                <h4> </h4>
            </div>
        </div>
    </div>
   
</body>

標籤: ,

2014年1月12日 星期日

javascript 換頁bar

<script type="text/javascript">
//2014/01/11

//nowPage 現在頁數
//totalitem 總共有幾筆資料
//pageShow 一頁要show幾筆資料
function pageList(nowPage, totalitem, pageShow) {

    var pagesPerGroup = 6;   // pages to be display in one bar
    var pageStr = "";

    var notPageCss = "style='border: 1px solid #C0C0C0; width: 20px; height: 30px; text-align:center;font-family:Microsoft YaHei; color:#555555; font-size:14px; cursor: pointer;'";
    var thisPageCss = "style='border: 1px solid #C0C0C0; width: 20px; height: 30px; text-align:center;font-family:Microsoft YaHei; color:#FFFFFF; font-size:14px; cursor: pointer; background-color: #888888;'";
    //debugger;

    if (totalitem / pageShow < pagesPerGroup) {
        if (totalitem % pageShow == 0) {
            pagesPerGroup = totalitem / pageShow;
        }

        else {
            pagesPerGroup = totalitem / pageShow + 1;
        }
    }

    pageStr += "<table style='margin: auto;'>";
    pageStr += "<tr>";

    if (nowPage != 1) {
        pageStr += "<td style=' width:50px;border: 1px solid #C0C0C0; height: 30px; text-align:center;font-family:Microsoft YaHei; color:#555555; font-size:14px; cursor: pointer;' onclick=\"ChangePage(" + (parseInt(nowPage) - 1) + ", " + totalitem + ", " + pageShow + ");\">上一頁</td>";
    }

    for (var i = 1; i <= pagesPerGroup; i++) {
        var changePage;

        if (nowPage <= 3) {
            if (i == nowPage) {
                pageStr += "<td id='page" + i + "' onclick='ChangePage(" + i + ", " + totalitem + ", " + pageShow + ");' " + thisPageCss + ">" + i + "</td>";
            }
            else {
                pageStr += "<td id='page" + i + "' onclick='ChangePage(" + i + ", " + totalitem + ", " + pageShow + ");' " + notPageCss + ">" + i + "</td>";
            }
        }

        else if (nowPage >= totalitem / pageShow - 2) {

            changePage = Math.floor(totalitem / pageShow - pagesPerGroup + i);

            if (changePage == nowPage) {
                pageStr += "<td id='page" + changePage + "' onclick='ChangePage(" + changePage + ", " + totalitem + ", " + pageShow + ");' " + thisPageCss + ">" + changePage + "</td>";
            }
            else {
                pageStr += "<td id='page" + changePage + "' onclick='ChangePage(" + changePage + ", " + totalitem + ", " + pageShow + ");' " + notPageCss + ">" + changePage + "</td>";
            }
        }

        else {

            changePage = (i + parseInt(nowPage) - 3);

            if (changePage == nowPage) {
                pageStr += "<td id='page" + changePage + "' onclick='ChangePage(" + changePage + ", " + totalitem + ", " + pageShow + ");' " + thisPageCss + ">" + changePage + "</td>";
            }
            else {
                pageStr += "<td id='page" + changePage + "' onclick='ChangePage(" + changePage + ", " + totalitem + ", " + pageShow + ");' " + notPageCss + ">" + changePage + "</td>";
            }
        }

    } //for

    if(nowPage != Math.ceil(totalitem / pageShow)){
        pageStr += "<td style=' width:50px;border: 1px solid #C0C0C0; height: 30px; text-align:center;font-family:Microsoft YaHei; color:#555555; font-size:14px; cursor: pointer;' onclick=\"ChangePage(" + (parseInt(nowPage) + 1) + ", " + totalitem + ", " + pageShow + ");\">下一頁</td>";
    }

    pageStr += "</tr>";
    pageStr += "</table>";


    $("#pager1").html(pageStr);
}
</script>


<script type="text/javascript">
$(function () {

    nowPage = 1;   //nowPage 現在頁數
    totalitem = 150;   //totalitem 總共有幾筆資料
    pageShow = 10;   //pageShow 一頁要show幾筆資料

    ChangePage(nowPage, totalitem, pageShow);

         
});

var nowPage;
var totalitem;
var pageShow;

//換頁
function ChangePage(nowPage, totalitem, pageShow) {
    pageList(nowPage, totalitem, pageShow);

    //alert(nowPage);
}

</script>

標籤: ,

2013年12月20日 星期五

Jquery 衝突問題 ('$' 和 'Jquery')

<script src="http://某網址/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type='text/javascript'>
var jQuery132 = jQuery.noConflict(true);
</script>


加載後用 jQuery132 取代 $
jQuery132(function(){ alert('test') });


出處:http://www.jb51.net/article/24187.htm

標籤:

2013年12月12日 星期四

Jquery 滾輪滑動

function ScrollContral(objStr){

var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
    $body.animate({
        scrollTop: $(objStr).offset().top - 300 //滑動的位子
    }, 600);
     
}

標籤:

2013年8月14日 星期三

Html CheckBox 判斷是否點選

判斷checkbox是否有點選
$('#chkbox01').is(':checked');



修改checkbox的checked
$('#chkbox01').prop('checked', 'true');

標籤:

2013年7月25日 星期四

Jquery-UI Table排序

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'></script>

<script type="text/javascript">

閱讀更多 »

標籤:

2013年7月23日 星期二

Jquery 剖析 JSON

var json = "{\"aaa\":\"111\",\"bbb\":\"222\"}";
var jsonData = eval( '(' + json + ')');   //轉為json格式
 
$.each(jsonData, function (index, item) {
    alert(index + ": " + item);
});

標籤:

2013年7月22日 星期一

Jquery AJAX

前台:
<input id="Button1" type="button" value="回復" onclick="SelectChange()"/>
function SelectChange() {
        var str1 = "test";

        var ajaxUrl = 'SelectUpdata.ashx';
        var data = { s1: str1 };
        $.ajax({
            async: false,
            type: 'POST',
            url: ajaxUrl,
            data: data,
            dataType: 'text',
            success: function (s1) {    //執行成功後接收回傳值
                alert(s1);
            },
            complete: function () {    //執行結束
                alert('OK');
             },
             beforeSend: function () {    //開始執行
                 alert('請稍等');
             }

        });

    }

後台:
.ashx
string select = context.Request["s1"];
context.Response.ContentType = "text/plain";
context.Response.Write(select );

標籤: ,