2013-01-08 56 views
0

我有兩個div追加HTML輸出到不同的div

<div id="ResultsId"> 
    Here are the results from the session!<br> 
</div> 

<div id="DatesSearchResultsId"> 
    <a href="#" onclick="SearchDateAjax('DatesSearchResultsId');">Click here to search by date</a> 
    <form name="dateSearch" action="searchbydate.php" method="post"> 
    date: <input type="date" name="date"><br> 
</form> 
</div> 

如何將HTML輸出追加從下面的代碼來使用AppendTo的ResultsId股利()方法?我似乎無法得到它的工作:

function SearchDateAjax(DatesSearchResultsId){ 
    $.ajax({ 
     type: "POST", 
     url: "searchbydate.php", 
     cache: false, 
     data: "name=Peter&location=Sheffield&date=" + $('input[name="date"]').val(), 
     success: function(html, status){ 
     $("#"+ResultsId).append(html); 
     //$('#status').append(status); 
     } 
    }); 
} 
+0

ID必須是唯一的!改爲使用類 –

+0

ResultsId未定義。您的參數稱爲DatesSearchResultsId。 – algorhythm

回答

1

既然你想要的div的ID是「ResultsId」,你會使用$('#ResultsID')選擇它。您目前有$("#"+ResultsID),它會將變量ResultsID的值添加到「#」。

1

看來你錯了什麼。試試這個:

$("#ResultsId").append(html);