This article implements the following features:
1. Click the text to change to the text box and select the text
2. Modify the contents of the text box
3. Click outside the text box to change the text box again to the modified text, if it is deleted text, display the default prompt text
4. Synchronizing updates to SQL database content
The first is the HTML Template section:
1 <{if!empty ($img _list)}>2 <{foreach$img _list as $kk=>$VV}>3 <Divclass= "Item-box Radius3">4 <ahref= "<{$vv [' Image ']}>"Target= "_blank">5 <Divclass= "Item-image">6 <imgsrc= "<{$vv [' Image ']}>?imageview/0/w/260/q/85" />7 </Div>8 </a>9 <Divclass= "Item-desc" >Ten <span class= "Item-desc-span"><{$vv [' name ']} ></ span > One <input type= "hidden" name= "image_id" value = "<{$vv [' id ']}>" /> A </Div> - <Divclass= "Item-op"> - the <{Date(' y-m-d h:i:s ', $vv [' Add_time '])}> - <Divclass= "Opabs"> - <{if$vv [' status ']==0}> - <spanclass= "Op"onclick= "Set_cover (<{$vv [' id ']}>)" >Set as cover</span> + <{/if}> - <spanclass= "Op"onclick= "Image_del (<{$vv [' id ']}>)" >Delete</span> + A at - </Div> - </Div> - </Div> - <{/foreach}> - <{/if}>
To do this again is to process the script:
<script type= "Text/javascript" >$ (function () {$ (". Item-desc-span"). Click (function () {var span_str = $ (this); var Ex_desc_str = Span_str.text (); var input_str = $ ("<input type= ' text ' class= ' edittxt ' name= ' desc ' value= '" +ex_desc_str+ "'/>"); Span_str.html ( INPUT_STR); Input_str.click (function () {return false;}); Input_str.trigger ("Focus"); Input_str.select ();//input loses focus when input_str.blur (function () {var To_desc = $ (this). Val (); var id = $ (this). Parent (). Next (' input '). Val (); $.ajax ({type: ' POST ', url: '/club_image/set_desc ', DataType: ' JSON ', data:{' ID ': ID, ' desc ': To_desc}, Success:function (data) {if (data.suc Cess==1) {if (To_desc) {span_str.html (TO_DESC); }else{span_str.html (' no description '); }}else{span_str.html (EX_DESC_STR); alert ("Background error:" +data.msg);} }, Error:function (data) {alert ("Ajax error"); RET = FalsE } });});/ /press ENTER when Input_str.keydown (function (event) {if (Event.keycode = =) {var To_desc = $ (this). Val (); var id = $ (this). Parent (). Next (' input '). Val (); $.ajax ({type: ' POST ', url: '/club_image/set_desc ', DataType: ' json ', data:{' ID ': ID, ' desc ': To_desc}, Success:function (data) { if (data.success==1) {if (To_desc) {span_str.html (TO_DESC); }else{span_str.html (' no description '); }}else{span_str.html (EX_DESC_STR); alert ("Background error:" +data.msg);} }, Error:function (data) {alert ("Ajax error"); ret = false; } }); }});});}); </script>
jquery realizes the text box after clicking the text, modifying the Send background save