JQUERY AJAX为每个循环定制属性 [英] JQUERY AJAX for each loop custom attributes
问题描述
这个问题与我昨天询问的另一个问题有关,它的链接是:
通过ajax解析jQuery中的HTML到元素中,并替换页面上的每个对应元素
基本上我想用ajax调用一个php页面,并用响应中的元素替换页面上的相应元素。我在回答中得到了以下函数:
$ $ $ data $ .filter('。maindiv')。each(function(索引)
/ *this是当前的回应* /
$('#'+ this.id).replaceWith(this);
});
上面的函数很好,当我想要替换的div有一个正规的id =但是如果使用a像gid =自定义属性,例如它不会工作。如何解决此问题?
谢谢 您可以选择带有gid属性的节点:
$('[gid]')。replaceWith(this);
通过只选择具有您想要的gid值的节点,您甚至可以更精确
$('[gid =hello]')。replaceWith(this);
希望它有帮助
This question is related to another one I asked yesterday and its link is: Parse HTML in jquery through ajax into elements and replace each corresponding on page
Basically i want to call a php page with ajax and replace the elements in the response with the corresponding ones on the page. I got the following function in an answer:
$(data ).filter('.maindiv').each(function (index)
/* "this" is the current div in response*/
$('#'+this.id).replaceWith(this);
});
The above function woeks well when the div I want to replace has a regular id= but if use a custom attribute like gid= for example it won't work. How can i fix this??
Thanks
You can select node with a gid attribute with:
$('[gid]').replaceWith(this);
you can even be more precise by selecting only the node which has the gid value you want
$('[gid="hello"]').replaceWith(this);
Hope it helps
这篇关于JQUERY AJAX为每个循环定制属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!