jQuery新手問題
[i=s] 本帖最後由 inkiness 於 2010-8-15 20:48 編輯 [/i]我這裡是在second.html用ajax從first.html拿資料
first.html[code]<div id="first">第一行</div>
<div id="third">第三行</div>[/code]second.html[code]<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
<input type="button" id="change" value="Change" />
<div id="second">第二行</div>
<script type="text/javascript">
$("#change").click(function() {
$.ajax({
type: "GET",
url: "first.html",
dataType: "html",
success: function(data){
alert(data);
$("#second").html(data);
}
});
});
</script>[/code]data返回時是<div id="first">第一行</div>
<div id="third">第三行</div>
我要怎樣才可從data中只拿到id=third (第三行) 這個 可以先把字串塞入 jQuery 變成物件,再以 selector 操作。
[code js]
var $html = $('<div>' + html + '</div>');
var new_str = $html.find("#thrid")[0];
$("#second").html(new_str);
[/code] 謝謝大大幫忙:loveliness:
頁:
[1]