代码之家  ›  专栏  ›  技术社区  ›  Trip

更新表单时,是否保存和替换文本,或避免更新文本?

  •  0
  • Trip  · 技术社区  · 14 年前

    我在jquery中有一个表单,通过一个简单的Ajax调用更新所有图像,以重新加载整个页面。不幸的是,标题也包含在那个表单中,当我开始写作时,我的标题会被覆盖。

    那么你会怎么保存它们呢?

    你会…

    1. 在Ajax调用之前保存它们,然后在调用之后替换它们?

    2. 避免同时更新标题?

    后者似乎是最佳选择,我只是不完全确定如何实现调用Ajax调用,但是 只是更新图像 .

    我亲爱的更新者

    $.extend({
      PhotoUpdater: {
        startUpdate: function(organization, gallery){
          url = "/organizations/" + organization + "/media/galleries/" + gallery + "/edit_photo_captions"
          timer = window.setTimeout(function(){
           $.PhotoUpdater.doUpdate(url)
          }, 5000) 
        },
        stopUpdate: function(){
          clearTimeout(timer);
          timer = 0;
        },
        doUpdate: function(url){
          $.ajax({type: "GET", url: url, dataType: "script"});
        },
        resetValues: function(){
          setTimeout(function(){ $("body").data("edit_photos_closed", "false"); 
                                 $.PhotoUpdater.stopUpdate();
          }, 3000 );
        }
      }
    });
    

    我的HTML

    <div class="alpha grid_4 zebraCaption">
          <img src="/tumblr_l0x861Yc5M1qbxc42o1_400.jpg" id="thumb_216" alt="Trippy Long Stockings's amazing picture">
          <br>
          <label for="gallery_photos_attributes_0_caption">Caption</label>
          <br>
          <input type="text" style="width: 236px;" size="35" name="gallery[photos_attributes][0][caption]" maxlength="35" id="gallery_photos_attributes_0_caption">
          <br>
          <a class="button_small facebox_window" href="/organizations/1/media/galleries/26/photos/216/edit_facebox_captions?captions_screen=true">edit crop</a>
          <a id="remove_crop_216" class="button_small remove_crop_button" href="http://localhost:3000/photos/216/toggle_crop">remove crop</a>
      </div>
    
    1 回复  |  直到 13 年前
        1
  •  0
  •   methodin    14 年前

    var imgArray = {JSON ARRAY FROM AJAX}
    $('img').each(function(index){
        $(this).attr('src',imgArray[index]);
    });