我有一个来自Ajax加载源的HTML字符串.在将HTML放入文档之前,我想从此字符串中的对象(图像)获取一些属性.
我有类似的东西:
$.ajax({
url: uri+'?js',
success: function(data) {
var htmlCode = $(data).html();
$('#otherObject').html(data);
}
});
Run Code Online (Sandbox Code Playgroud)
如何src从此HTML字符串中获取属性(例如)?
我在使用jQuery 解析HTML字符串时询问如何在html字符串上使用jQuery.这一切都有效,但当我将它应用于ajax时 - 它不起作用.这是代码.
<script>
var url = 'moo.html';
$.ajax({
url: url,
success: function ( code )
{
html = $(code);
html.each(function() {
alert( $(this).html() );
});
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
moo.html包含
<div id='test'>zebra</div>
<div id='foo'>bar</div>
Run Code Online (Sandbox Code Playgroud)
我怎么能得到斑马和酒吧?