duanan6043 2013-10-09 14:43
浏览 17

用输入替换标题并更新数据库上的标题

Hi I'm trying to replace a title when clicking on it by a text input in order to modify the title and then submit the modification to the database, I'm using this code :

<div style="font-size: 70%;"><h2 class="outer"><?php echo $designation; ?> </h2></div>

this div is loaded using another script and therefore is not on the original page, so I think we must use the delegate method.

Here is the jquery script I'm using to turn its background color to pink:

<script src="jquery-1.10.2.min.js">
  $(document).ready(function(){
     $("#right").delegate("h2","click",function(){
       $("h2").css("background-color","pink");
     });
  });
 </script>

Any idea how to replace the title in this div by a text input tag ? and any idea how to submit the modification to the database once I click outside the input field ? thank you

  • 写回答

1条回答 默认 最新

  • dpxnrx11199 2013-10-09 14:48
    关注
    • There is no click handler in you code, you can use .on() method
    • You should use another script tag for loading .js files, your markup is invalid
    • input element doesn't have closing tag, you should remove the </input>

      <script src="jquery-1.10.2.min.js"></script>
      
      <script>
         $(document).ready(function(){ // When the DOM is ready
            $(".outer").on('click', function() {
               if ( this.children.length ) return;
               var text = $.trim(this.innerHTML);
               $("<input>").val(text)
                           .appendTo($(this).empty())
                           .focus();
            }).on('blur', 'input', function() {
               // Listening to blur event 
               // for replacing the element with it's value
               $(this).replaceWith( $.trim(this.value) );
            })
         })
      </script>
      

    http://jsfiddle.net/3FKzH/

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题