用jquery寫一個無重新整理評論功能

來源:互聯網
上載者:User

標籤:style   blog   http   java   color   io   2014   cti   

<1>

<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script src="Jquery/jquery-1.10.2.js" type="text/javascript"></script>    <script type="text/javascript">        //========================================================設定樣式        $(function () {            var isFirst = true;            $("#text1").css("color", "grey").focus(function () {                if (isFirst) //判斷使用者是否第一次輸入,如果是第一次輸入,就將當前控制項的值設為空白                       $(this).val("");                $(this).css("color", "Black")            });            $("#text1").bind("keydown", function () {//#text1控制項綁定 keydown事件,當它被按下的時候就觸發function()匿名函數,將isFirst設為false【這時候將isFirst設為fasle,那就麼代表它不是第一次輸入了。所以第二次點擊#text1控制項的時候它就不會將#text1的值設為空白了】                  isFirst = false;            });            $("#text1").blur(function () {                if ($(this).val().length <= 0) {   //如果在失去焦點的時候使用者名稱的長度<=0的話就重新提示使用者"請輸入使用者名稱"                      $(this).css("color", "grey").val("請輸入使用者名稱")                }            })        })        $(function () {            var isFirst = true;            $("#text2").css("color", "grey").focus(function () {                if (isFirst) //判斷使用者是否第一次輸入,如果是第一次輸入,就將當前控制項的值設為空白                       $(this).val("");                $(this).css("color", "Black")            });            $("#text2").bind("keydown", function () {//#text1控制項綁定 keydown事件,當它被按下的時候就觸發function()匿名函數,將isFirst設為false【這時候將isFirst設為fasle,那就麼代表它不是第一次輸入了。所以第二次點擊#text1控制項的時候它就不會將#text1的值設為空白了】                  isFirst = false;            });            $("#text2").blur(function () {                if ($(this).val().length <= 0) {   //如果在失去焦點的時候使用者名稱的長度<=0的話就重新提示使用者"請輸入使用者名稱"                      $(this).css("color", "grey").val("請輸入評論的內容")                }            })        })        //==========================================================================實際內容        $(function () {            $("#btn1").click(function () {                var tr = $("<tr><td>" + $("#text1").val() + ":" + "</td><td>" + $("#text2").html() + "</td></tr>")                $("#table1").append(tr);            })                    })    </script></head><body><p>.......這是我的文章,請大家評論。</p><table id="table1"></table><input type="text"  value="請輸入使用者名稱" id="text1"/><br /><textarea cols="20" rows="8" id="text2">請輸入評論內容</textarea><input type="button" value="提交" id="btn1"/></body></html>



聯繫我們

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