2017-04-02 9 views
-1

ウェブページ上に動的に作成されたテーブルがあります。テーブルには3つのカラム、 'ファイル名'、 'ファイルルル'、および 'ダウンロード'というテキストノードの列があります。ユーザーが特定の行の「ダウンロード」をクリックした場合、ここでこのjavascript - 動的テーブルから値を取得する方法

filename  fileurl  download 
file1  www.pathtofile1 download 
file2  www.pathtofile2 download 
file3  www.pathtofile3 download 

要件などの いくつかのものがあり、私はその行の「ファイル名」と「fileurl」の対応する値を取得する必要があります。 どうすればいいですか?

+0

十分なはずです。ドゥー –

答えて

0

これは、あなたの要件を満たしているコードを記述する必要があり

$("table tr .download").click(function(){ 
 
    var row = $(this).closest("tr"); 
 
    var name = row.find(".name").html(), 
 
     url = row.find(".url").html(); 
 
    console.log(name,url) 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
<tbody> 
 
<tr> 
 
    <td class="name">file1</td> 
 
    <td class="url">www.pathtofile1</td> 
 
    <td class="download">Download</td> 
 
</tr> 
 
<tr> 
 
    <td class="name">file2</td> 
 
    <td class="url">www.pathtofile2</td> 
 
    <td class="download">Download</td> 
 
</tr> 
 
<tr> 
 
    <td class="name">file3</td> 
 
    <td class="url">www.pathtofile3</td> 
 
    <td class="download">Download</td> 
 
</tr>

関連する問題