码迷,mamicode.com
首页 > 其他好文 > 详细

双击文本框,可编辑状态,当鼠标移走后

时间:2015-05-07 14:16:51      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

// JavaScript Document

$(function() { 
//获取class为caname的元素 
$(".caname").click(function() { 
    var td = $(this); 
    var txt = td.text(); 
    var input = $("<input type=‘text‘value=‘" + txt + "‘ style=‘width:23px;‘/>"); 
    td.html(input); 
    input.click(function() { return false; }); 
//获取焦点 
    input.trigger("focus"); 
//文本框失去焦点后提交内容,重新变为文本 
    input.blur(function() { 
    var newtxt = $(this).val(); 
//判断文本有没有修改 
  if (newtxt != txt) { 
    td.html(newtxt);
    var wid = $.trim(td.prev().text());
    var database=$("#database").val();
    $.ajax({
       type:"POST",
       
       url:"/admin.php/Index/modifypx",
       
       data:{id:wid,paixu:newtxt,database:database},
       
       dataType:"json",
       
       success:function(data){
          if(data ==1){
                    $.gritter.add({
                        // (string | mandatory) the heading of the notification
                        title: ‘修改排序成功‘,
                        // (string | mandatory) the text inside the notification
                        text: ‘ ‘,
                        time: 1000
                    });
                    window.location.reload();
             }else{
                    $.gritter.add({
                        // (string | mandatory) the heading of the notification
                        title: ‘修改排序失败‘,
                        // (string | mandatory) the text inside the notification
                        text: ‘ ‘,
                        time: 1000
                    });
             }
       }
    });
    
  } 
  else 
  { 
  td.html(newtxt); 
  } 
  }); 
  });
}); 




双击文本框,可编辑状态,当鼠标移走后

标签:

原文地址:http://www.cnblogs.com/muxiaoye/p/56c920f76b0ce6a7a0b0c5907d43d610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!