我有一个 PHP 文件,它将返回类似的内容
<div id="title">Add Us On Myspace!</div><img id="image" src="http://i39.tinypic.com/67jybs.png" alt="Add Us On Myspace!" />
这就是所谓的使用这个...
$.ajax({
url: "Tabnews.php",
success: function(tab1html){
$("#tabs-1").html(tab1html);
}
});
我需要在 jQuery 的变量中定义 #title 和 #image 的内容,以便我可以将它们写入其他位置。
我该怎么做?
最佳答案
这应该可以做到:
var $html = $(tab1html); // parse string into DOM structure
var $title = $html.filter('#title'); // keep the title
var $image = $html.filter('#image'); // keep the image
// add to whatever elements we want...
$('#my_element').append($title);
$('#my_other_element').append($image);
关于jQuery Ajax - 获取元素内部文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1081791/