jQuery的 - 与阿贾克斯
元件的负载我搜索了一段时间,但找不到我的问题一个有效的解决方案(对不起,如果我搜索错误)...... 我想有以下功能的一个等价元件装载有AJAX:jQuery的 - 与阿贾克斯
$(document).ready(function() {
$('.div-modal-text').css("background-color","red");
});
因此我使用以下代码:
$('#parent_id').on('action', '#id or class to be born', function to be performed());
在我的例子的父子结构是:#projectModals(DIV其内容是动态加载)> .. 。>。div-project-description> .div-modal-text
这相当于在我的例子下面的代码:
$('#projectModals').on('load', '.div-project-description', function() {
$(this).find('.div-modal-text').each(function() {
$(this).css("background-color","red");
});
});
我知道“负荷”不工作。对(),但我尝试了不同的选择,我无法找到任何工作。
感谢您的帮助!
编辑:这是我的(简单)的HTML代码:
<div id="projectModals"></div>
内容加载#projectModals使用Ajax:
<div class="row">
<div class="div-project-idcard">
column 1, don't bother too much about this column
</div>
<div class="div-project-description">
<div id="summary" class="div-modal-text">
Column2, text 1
</div>
<div id="purpose" class="div-modal-text"">
Column2, text 2
</div>
<div id="reforestation" class="div-modal-text">
Column2, text 3
</div>
<div id="certification" class="div-modal-text">
Column2, text 4
</div>
</div>
</div>
如果你在等待它通过加载ajax,考虑用$(window).ajaxSuccess()
代替:
$(window).ajaxSuccess(function(){
$('#projectModals .div-project-description .div-modal-text').each(function() {
$(this).css("background-color","red");
});
});
而不是'$('#projectModals.div-project-description .div-modal-text').css(“background-color”,“red”)' – 2014-11-03 08:26:02
谢谢,那是一个错字。现在修复。 – Scimonster 2014-11-03 08:26:41
据我所知,你想在ajax执行后改变一些背景颜色。
我认为这是最好的,使在阿贾克斯成功
$.ajax({
url: "some url",
data: {some data},
success: onAjaxSuccess,
});
然后操作;
function onAjaxSuccess(data){
//.. do things with data
var toExecute = $('#projectModals .div-project-description');
toExecute.find('.div-modal-text').each(function() {
$(this).css("background-color","red");
});
}
你会分享你的html代码吗? – 2014-11-03 08:18:58
你是否总是需要'.div-modal-text'的相同背景颜色?如果是这样,为什么不只使用CSS? – 2014-11-03 08:20:56
如何将您的内容加载到#projectModals中,发布该脚本 – SarathSprakash 2014-11-03 08:28:07