Ben*_*ock 1 html ajax jquery css-selectors
我有一个PHP文件将返回类似的东西
<div id="title">Add Us On Myspace!</div><img id="image" src="http://i39.tinypic.com/67jybs.png" alt="Add Us On Myspace!" />
Run Code Online (Sandbox Code Playgroud)
这是用这个来调用的......
$.ajax({
url: "Tabnews.php",
success: function(tab1html){
$("#tabs-1").html(tab1html);
}
});
Run Code Online (Sandbox Code Playgroud)
我需要在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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8713 次 |
| 最近记录: |