zoukankan      html  css  js  c++  java
  • jquery 如何将文本置换为input框,并修改其内容

    //html代码
    <td title="{$doctor.reason}"><span class="doc_reason" value="{$doctor.evalue_id}">{$doctor.reason|htmlspecialchars|trim|msubstr=0,35}</span></td>
    //JS代码
    
    // 使用live可以给动态添加的元素绑定事件
     $('td span.doc_reason').live('click',function() {
            var evalue_id       = $(this).attr('value');
            var span_reason     = $(this).text();
            var td              = $(this).parent();
            var doc_reason      = $.trim($(td).attr('title'));
            var html            = '<textarea style="450px;height:30px;">'+doc_reason+'</textarea>';
            td.html(html);
            var textarea        = $('textarea');
           //先将textarea的内容置空,然后移入焦点,在插入内容,这样可以让焦点默认处于文本的最后面
            textarea.val('').focus().val(doc_reason);
            textarea.blur(function() {
                var new_doc_reason  = textarea.val();
                $.ajax({
                    type    : 'post',
                    data    : {
                        'evalue_id'   : evalue_id,
                        'doc_reason'  : new_doc_reason,
                    },
                    url     : '__URL__/mof_doc_reason',
                    dataType: 'text',
                    success : function(res) {
                        if(res == '0') {
                            alert('系统发生错误!修改失败!');
                            var _html   = '<span class="doc_reason" value="'+evalue_id+'">'+span_reason+'</span>';
                        }else {
                            var _html   = '<span class="doc_reason" value="'+evalue_id+'">'+res+'</span>';
                        }
                        td.attr('title',res);   
                        td.html(_html);
                    },
                });
            });
    
        });
    //PHP 代码
    
        /*
            修改推荐理由
        */
        public function mof_doc_reason() {
            if(!$this->isPost())
                die('0');
            //接收数据
            $evalue_id         = $this->_post('evalue_id');
            $doc_reason     = $this->_post('doc_reason');
            //连接数据,修改数据
            $doctor_evalue     = M('doctor_evalue');
            $savedata['reason']     = $doc_reason;
            $res             = $doctor_evalue->where(array('evalue_id' => $evalue_id))->save($savedata);
            if($res === false)
                die('0');
            echo mb_substr($doc_reason,0,35,'utf-8');
        }
  • 相关阅读:
    优化SQL查询:如何写出高性能SQL语句
    提高SQL执行效率的16种方法
    Spring Ioc DI 原理
    java内存泄漏
    转:js闭包
    LeetCode Best Time to Buy and Sell Stock III
    LeetCode Best Time to Buy and Sell Stock with Cooldown
    LeetCode Length of Longest Fibonacci Subsequence
    LeetCode Divisor Game
    LeetCode Sum of Even Numbers After Queries
  • 原文地址:https://www.cnblogs.com/lxdd/p/4026059.html
Copyright © 2011-2022 走看看