jquery realizes the text box after clicking the text, modifying the Send background save

Source: Internet
Author: User

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>&nbsp;     +         <{/if}> -             <spanclass= "Op"onclick= "Image_del (<{$vv [' id ']}>)" >Delete</span> +             &nbsp;     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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.