2012-07-19 81 views
0

Java腳本代碼股利的HTML代碼沒有從HTML代碼中提取

$("#category select").change(function(){ 
var category = $('select option:selected').html(); 

$.ajax({ 
    type:"Post", 
    url:"collectiepost.php", 
    data:"category="+category, 
    cache:"false", 
    success:function(html){ 

$("select").html($(html).find("option.category")); 
$("#test").html($(html).find("#testdata")); 
    } 
    }); 
    }); 
}); 

在該頁面collectiepost.php

<select id="ontwerper"> 
<option class="desinger">vikas</option> 
</select> 

<select id="category"> 
<option class="category">cloth1</option> 
<option class="category">cloth2</option> 
</select> 

<div id="testdata">test data</div> 

HTML輸出需要輸出

<select> 
<option class="category">cloth1</option> 
<option class="category">cloth2</option> 
</select> 

<div id="test"> 
<div id="testdata">test data</div> 
</div> 

問題

,但我得到這些輸出,而不在下面一行div標籤

<select> 
<option class="category">cloth1</option> 
<option class="category">cloth2</option> 
</select> 

回答

0

在 「div #test」 刪除空格:

$("div #test").html($(html).find("div #testdata")); 
+0

我已經做了這樣的也$( 「#測試」)HTML($(HTML).find(「#測試數據」));但不工作 – 2012-07-19 12:25:28

+0

我的意思是什麼,改變這行'$( 「#DIV測試」)HTML($(HTML).find( 「#DIV TESTDATA」));'你有div'之間'空間'#測試'在兩個地方。發生了什麼事是,AJAX調用看起來與ID =「測試」元素的所有div元素,而不是尋找與ID =「測試」 div元素 – qais 2012-07-19 12:28:01

+0

看到我編輯的問題後,我的代碼是不能工作 – 2012-07-19 12:30:01

0

我認爲你可以得到這樣的:

<div id="test"> 
<div id="testdata">test data</div> 
</div> 

是因爲在你的html輸出中你沒有「test」div:

<select id="ontwerper"> 
<option class="desinger">vikas</option> 
</select> 

<select id="category"> 
<option class="category">cloth1</option> 
<option class="category">cloth2</option> 
</select> 

<div id="testdata">test data</div> 
No test div here 

$("div #test").html($(html).find("div #testdata"));失敗

包裹它是這樣的:

$('#testdata').wrap('<div id="test" />'); 
+0

I M希望得到

2012-07-19 12:33:06

+0

@vikastyagi包裹內這條線

test data
做到這點 – 2012-07-19 12:38:19