也許我搜索得很差,但到目前爲止我還沒有找到我的問題的答案。首先是Javascript函數的代碼:如何獲得一個隱藏的兄弟的div的內容到一個按鈕 - jQuery相關
<script>
function showComment(){
var $data = $(this).parent("td").contents("div.hiddenComment").text();
console.log($data);
alert($data);
return false;
}
</script>
我還包括了我正在處理的HTML代碼。基本上它是一個<table>
,在一個<td>
有一個<button>
和一個隱藏的<div>
。應在警告/對話框中顯示<div>
的內容。
<table class="center">
<thead>
<tr>
<th>Status</th>
<th>Datum</th>
<th>Zeit</th>
<th>Amount</th>
<th>Source</th>
<th colspan="2">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>status1</td>
<td>2013-04-04</td>
<td>06:30:38</td>
<td>3.646.268,00</td>
<td>SRC1</td>
<td>
<div class="hiddenComment">a comment</div>
<button name="showComment" type="button" href="#" class="showComment" onClick="showComment()">show</button>
</td>
<td><a href="#" class="addComment">add</a>
</td>
</tr>
<tr>
<td>status</td>
<td>2013-04-05</td>
<td>06:30:48</td>
<td>1.732.213,00</td>
<td>SRC2</td>
<td>
<div class="hiddenComment">an other comment</div>
<button name="showComment" type="button" href="#" class="showComment" onClick="showComment()">show</button>
</td>
<td><a href="#" class="addComment">add</a>
</td>
</tr>
.....
</body>
</table>
我想你可以從這段代碼中得到關於<table>
的想法。無論如何,我在搜索網絡之後所取得的最好成績是一條"undefined"
消息。
我應該注意:類.hiddenComment
有CSS屬性display:none
。
任何提示,技巧和竅門受到熱烈歡迎!
感謝您的時間和幫助。