Javascript 更新表单时,您会保存和替换文本,还是避免更新文本?
我在jQuery中有一个表单,通过一个简单的ajax调用更新所有图像,以重新加载整个页面。不幸的是,标题也包含在表格中,当我开始写作时,我的标题被覆盖了 那么你会怎么做来留住他们呢 你会Javascript 更新表单时,您会保存和替换文本,还是避免更新文本?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我在jQuery中有一个表单,通过一个简单的ajax调用更新所有图像,以重新加载整个页面。不幸的是,标题也包含在表格中,当我开始写作时,我的标题被覆盖了 那么你会怎么做来留住他们呢 你会 在ajax调用之前保存它们,在调用之后替换它们 避免同时更新标题 后者似乎是最好的选择,我只是不完全确定如何实现调用AJAX调用,而只是更新图像 我的甜蜜更新程序 $.extend({ PhotoUpdater: { startUpdate: function(organization, galle
$.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>
说明文字
您可以尝试以下方法:
如果页面上有10个图像,那么AJAX响应可能是一个包含10个img源的JSON数组。然后,您可以执行以下操作:
var imgArray = {JSON ARRAY FROM AJAX}
$('img').each(function(index){
$(this).attr('src',imgArray[index]);
});
但是,只有当您知道页面上图像的顺序,或者它们由ID标识时,这才有效。我不完全理解您的意思,但Json是一个很好的观点。如果有帮助的话,我在上面添加了我的HTML。谢谢Methodin。很难通过“更新页面上的所有图像”来了解您想要实现的目标。URL本身是否更改或图像的内容是否更改?它是否用HTML表单替换img,并在完成后返回img?它只是更新图像url。背景故事是图像正在处理。如果还没有完成的话,其中一些人会表现得很激动。所以我做了一个定期更新程序,可以更新整个html。所以我只需要重复那个url。