jQuery的阿贾克斯 - 获取元素内部文本 [英] jQuery Ajax - Get Elements Inner Text
本文介绍了jQuery的阿贾克斯 - 获取元素内部文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP文件,该文件将返回类似
I have a PHP file which will return something like
<div id="title">Add Us On Myspace!</div><img id="image" src="http://i39.tinypic.com/67jybs.png" alt="Add Us On Myspace!" />
这是使用这种所谓的...
This is called using this...
$.ajax({
url: "Tabnews.php",
success: function(tab1html){
$("#tabs-1").html(tab1html);
}
});
我需要在jQuery的变量定义#title和#image的内容,这样我就可以写的东西他们在哪里。
I need to define the contents of #title and #image in a variable in jQuery so I can write them else where.
我怎样才能做到这一点?
How can I do this?
推荐答案
这应该做到这一点:
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的阿贾克斯 - 获取元素内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文