JQuery小練習,JQuery練習

來源:互聯網
上載者:User

JQuery小練習,JQuery練習
1、加法計算機。兩個文字框中輸入數字,點擊【=】按鈕將相加的結果放到第三個文字框中。<script src="jquery-1.8.3.js"></script>    <script type="text/javascript">        $(function () {            $('#btn').click(function () {                var first = parseInt($('#btnFirst').val());                var second = parseInt($('#btnSecond').val());                var sum = first + second;                $('#btnResult').val(sum);            });        });    </script></head><body>    <input type="text" name="name" value="" id="btnFirst" />+    <input type="text" name="name" value="" id="btnSecond" />    <input type="button" name="name" value="=" id="btn" />    <input type="text" name="name" value="" id="btnResult" /></body>2、十秒鐘後協議文字框下的註冊按鈕才能點擊,時鐘倒數。設定可用性等jQuery未封裝方法:attr("")setInterval() <script type="text/javascript">        $(function () {            var i = 5;            var setId = setInterval(function () {                i--;                if (i <= 0) {                                        $('#btnShow').val('同意').attr('disabled', false);                    clearInterval(setId);                }                else {                    $('#btnShow').val('請仔細閱讀協議(' + i + ')');                }            }, 500);        });    </script>
<input type="button" name="name" value="請仔細閱讀協議(5)" id="btnShow" disabled="disabled" />3、無重新整理評論。(已做)  <script src="jquery-1.8.3.js"></script>    <script type="text/javascript">        $(function () {            $("#btn1").click(function () {                //建立一行和兩個單元格                $('<tr><td>' + $('#txt').val() + '</td><td>' + $('#textContent').val() + '</td></tr>').appendTo($("#tb"));            });        });    </script></head><body>    <table id="tb" style="border:1px solid red;">        <tr>            <td>                貓貓:            </td>            <td>                沙發耶!            </td>        </tr>    </table>    <br />    暱稱:<input type="text" id="txt" value="" /><br />    <textarea id="textContent" rows="10" cols="15"></textarea><br />    <input type="button" value="評論" id="btn1" /></body>4、案例1:建立若干個輸入文字框,當游標離開文字框的時候如果文字框為空白,則將文字框背景色設定為紅色,如果不為空白則為白色。提示:焦點進入控制項的事件是focus,焦點離開控制項的事件是blur。 $(function () {            $('input').blur(function () {                if ($(this).val().length == 0) {                    $(this).css('backgroundColor', 'red');                }                else {                    $(this).css('backgroundColor','');                }            });        });5、案例:選擇球隊,兩個ul。被懸浮行高亮顯示(背景是紅色),點擊球隊將它放到另一個的球隊列表。//清除所有事件。.unbind();<script type="text/javascript">        $(function () {            //滑鼠經過            $('#uul li').mouseover(function () {                $(this).css('cursor', 'pointer').css('backgroundColor', 'red');            //滑鼠離開            }).mouseout(function () {                $(this).css('cursor', 'pointer').css('backgroundColor', '')                //滑鼠點擊                .click(function () {                    $(this).unbind().removeAttr('style').appendTo($('#ul2'));                });            })        });    </script>1、加法計算機。兩個文字框中輸入數字,點擊【=】按鈕將相加的結果放到第三個文字框中。<script src="jquery-1.8.3.js"></script>    <script type="text/javascript">        $(function () {            $('#btn').click(function () {                var first = parseInt($('#btnFirst').val());                var second = parseInt($('#btnSecond').val());                var sum = first + second;                $('#btnResult').val(sum);            });        });    </script></head><body>    <input type="text" name="name" value="" id="btnFirst" />+    <input type="text" name="name" value="" id="btnSecond" />    <input type="button" name="name" value="=" id="btn" />    <input type="text" name="name" value="" id="btnResult" /></body>2、十秒鐘後協議文字框下的註冊按鈕才能點擊,時鐘倒數。設定可用性等jQuery未封裝方法:attr("")setInterval() <script type="text/javascript">        $(function () {            var i = 5;            var setId = setInterval(function () {                i--;                if (i <= 0) {                                        $('#btnShow').val('同意').attr('disabled', false);                    clearInterval(setId);                }                else {                    $('#btnShow').val('請仔細閱讀協議(' + i + ')');                }            }, 500);        });    </script>
<input type="button" name="name" value="請仔細閱讀協議(5)" id="btnShow" disabled="disabled" />3、無重新整理評論。(已做)  <script src="jquery-1.8.3.js"></script>    <script type="text/javascript">        $(function () {            $("#btn1").click(function () {                //建立一行和兩個單元格                $('<tr><td>' + $('#txt').val() + '</td><td>' + $('#textContent').val() + '</td></tr>').appendTo($("#tb"));            });        });    </script></head><body>    <table id="tb" style="border:1px solid red;">        <tr>            <td>                貓貓:            </td>            <td>                沙發耶!            </td>        </tr>    </table>    <br />    暱稱:<input type="text" id="txt" value="" /><br />    <textarea id="textContent" rows="10" cols="15"></textarea><br />    <input type="button" value="評論" id="btn1" /></body>4、案例1:建立若干個輸入文字框,當游標離開文字框的時候如果文字框為空白,則將文字框背景色設定為紅色,如果不為空白則為白色。提示:焦點進入控制項的事件是focus,焦點離開控制項的事件是blur。 $(function () {            $('input').blur(function () {                if ($(this).val().length == 0) {                    $(this).css('backgroundColor', 'red');                }                else {                    $(this).css('backgroundColor','');                }            });        });5、案例:選擇球隊,兩個ul。被懸浮行高亮顯示(背景是紅色),點擊球隊將它放到另一個的球隊列表。//清除所有事件。.unbind();<script type="text/javascript">        $(function () {            //滑鼠經過            $('#uul li').mouseover(function () {                $(this).css('cursor', 'pointer').css('backgroundColor', 'red');            //滑鼠離開            }).mouseout(function () {                $(this).css('cursor', 'pointer').css('backgroundColor', '')                //滑鼠點擊                .click(function () {                    $(this).unbind().removeAttr('style').appendTo($('#ul2'));                });            })        });    </script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.