使用Jquery實現點擊文字後變成文字框且可修改

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   使用   sp   on   資料   

 1 $(function() { 2 //擷取class為caname的元素 3 $(".caname").click(function() { 4 var td = $(this); 5 var txt = td.text(); 6 var input = $("<input type=‘text‘value=‘" + txt + "‘/>"); 7 td.html(input); 8 input.click(function() { return false; }); 9 //擷取焦點10 input.trigger("focus");11 //文字框失去焦點後提交內容,重新變為文本12 input.blur(function() {13 var newtxt = $(this).val();14 //判斷文本有沒有修改15 if (newtxt != txt) {16 td.html(newtxt);17 /*18 *不需要使用資料庫的這段可以不需要19 var caid = $.trim(td.prev().text());20 //ajax非同步更改資料庫,加參數date是解決緩衝問題21 var url = "../common/Handler2.ashx?caname=" + newtxt + "&caid=" + caid + "&date=" + new Date();22 //使用get()方法開啟一個一般處理常式,data接受返回的參數(在一般處理常式中返回參數的方法 context.Response.Write("要返回的參數");)23 //資料庫的修改就在一般處理常式中完成24 $.get(url, function(data) {25 if(data=="1")26 {27 alert("該類別已存在!");28 td.html(txt);29 return;30 }31 alert(data);32 td.html(newtxt);33 });34 */35 }36 else37 {38 td.html(newtxt);39 }40 });41 });42 }); 

 

使用Jquery實現點擊文字後變成文字框且可修改

聯繫我們

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