我们有如下一个div结构:AJAX后更新DIV内容发布
<!-- main.php starts -->
<div class="main">
<div class="one">
<span class="buttonEdit">EDIT</span>
</div>
<div class="two">Content</div>
<div class="editBox">
<!-- abc.php which is loaded onClick -->
<textarea class="editArea"></textarea>
<span class="buttonSave">SAVE</span>
<!--abc.php ends -->
</div>
</div>
<!-- main.php ends -->
我用jQuery是这样的:
$(document).ready(function() {
//SAVE BUTTON
$(".buttonSave").click(function(){
//AJAX SAVE HERE
$.post("save.php",function(msg){
var newContent;
newContent = $(".editArea").val();
$(this).parents(".main").find('.two').text(newContent);
});
});
的过程: 在点击编辑按钮,一个外部页面(abc.php)将通过jQuery的加载函数加载到div(class =“editBox”)。 编辑和保存之后,textarea中的内容必须显示在div中(class =“two”)。
重要有几个类似的块和类名相同。 jQuery写在abc.php这是一个外部文件。在AJAX中可以使用'find'和'this'吗?
解决方案需要:我们需要jQuery部分。紧急!
上的jsfiddle:http://jsfiddle.net/JerryJones/PacTs/
您应该添加IDS所有块,你说:“有几个类似的块”。
然后用ajax显示特定块中的数据。 –