// HTML code <td title= "{$doctorclass=" Doc_reason "value=" {$doctor. evalue_id} " >{$doctor. reason| Htmlspecialchars| Trim|msubstr=0,35}</span></td>
//JS code//Use Live to bind events to dynamically added elements$ (' TD Span.doc_reason '). Live (' click ',function() { varevalue_id = $ (this). attr (' value ')); varSpan_reason = $ (this).text (); varTD = $ (this).parent (); varDoc_reason = $.Trim($ (TD). attr (' title '))); varhtml = ' <textarea style= ' width:450px;height:30px; " > ' +doc_reason+ ' </textarea> '; TD.HTML (HTML); varTEXTAREA = $ (' textarea '); //The contents of the textarea are left blank and then moved into focus, inserting content so that the focus defaults to the last face of the textTextarea.val ("). focus ().Val (Doc_reason); TextArea. Blur (function() { varNew_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 (' The system has an error! Modification failed! ‘); 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 Code /*suggested reasons for modification*/ Public functionMof_doc_reason () {if(!$this-isPost ()) die(' 0 '); //Receive Data $evalue _id=$this->_post (' evalue_id '); $doc _reason=$this->_post (' Doc_reason '); //Connect data, modify data $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 '); EchoMB_SUBSTR ($doc _reason, 0,35, ' Utf-8 '); }
How jquery replaces text with the input box and modifies its contents