zoukankan      html  css  js  c++  java
  • 还是一个鼠标点击td变成input,失去焦点更新数据库

    之前有发过一个php的,http://www.corange.cn/archives/2010/04/3576.html
    这两天又研究了一个,这个也是亲自测试过的
    html部分
    <Tr>
    <Td width="17" class="catid"><?php echo $row['bigclassid']?></Td>
    <Td width="133" ><span class="listorder" title="点击修改"><?php echo $row['sort']?></span></Td>
    </Tr>
    注意上面第一列一定要放在第一列,就是id那一列
    js部分
    <script>
    $('.listorder').click(function(e){
    var catid = $(this).parent().siblings("td:eq(0)").text();//获取同一行上 第一列中的id值
    var listorder_now_text = $(this).text();//获取listorder中的内容 先保存起来
    $(this).text("");//设置内容为空
    var list_form = '<input type="text" value="'+listorder_now_text+'" size=2 class="listorder_input" />' ;
    $(this).parent().append(list_form); //插入 input框
    $(".listorder_input").focus();

    //自定义一个div 提示修改中
    var loading = '<div id="loading"><img src="loading.gif" alt="修改中..." width="20" /></div>';
    $(this).parent().append(loading);
    $('#loading')
    .css({
    "color" : "red" ,
    "display" : "none"
    })
    //定义ajax的全局事件
    $(this).ajaxStart(function(){
    $('#loading').show();
    })
    $(this).ajaxStop(function(){
    $('#loading').remove();
    })

    $(".listorder_input").blur(function(){
    var thislist = $(this).siblings(); //取得同级的标签 即 修改后需要显示的 listorder
    $.post("update_bigclassname_3.php",{
    action : "mod_listorder",
    catid : catid ,
    listorder : $(this).attr("value")
    } , function(data, textStatus){
    $(thislist).text(data);
    }
    );//end .post
    $(this).remove();
    })//end function blur
    })// end function click

    </script>
    更新部分就是普通文件,
    <?php
    mysql_select_db($database_lr, $lr);
    $bigclassid = trim($_REQUEST['catid']);
    $sort = trim($_REQUEST['listorder']);

    $update_sql = "update bigclass set sort='$sort' where bigclassid='$bigclassid'";
    $result = mysql_query($update_sql);
    echo $sort;
    ?>
    只要注意到上面那个echo $sort;就是更新完毕后传递的值
    同样要用到jquery,请自己下载后调试
    这个感觉比之前那个效果更好,当然看你自己喜欢哪个

    原文地址:http://www.corange.cn/archives/2010/04/3584.html

  • 相关阅读:
    .Net中的AOP系列之《方法执行前后——边界切面》
    【信息学奥赛一本通】题解目录
    7219:复杂的整数划分问题
    1039 数的划分
    7215:简单的整数划分问题
    大整数阶乘的计算
    大数阶乘的位数和精确值计算【转】
    Window.Open详解
    在asp.net中显示PDF的方法:
    位运算技巧
  • 原文地址:https://www.cnblogs.com/zerogo/p/2209080.html
Copyright © 2011-2022 走看看