2014-12-05 194 views
0

我想將兩個不同表格的行值的值傳遞給javascript函數onclick on工具提示數據。將值傳遞給javascript函數onclick

請找到小提琴http://jsfiddle.net/0w9yo8x6/34/

下面是示例代碼:

<table border="1"> 
<tr> 
<td> 
<span style="float:left;">Table1Title</span> 
<span style="float:right">MyData</span> 
</td> 
</tr> 

<tr> 
<td> 
<table width="200px"> 
<tr> 
<td>Data1 <img class="one" data-title="Data1" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" /> 
</td> 
</tr> 

<tr> 
<td>Data2 <img class="one" data-title="Data2" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" /> 
</td> 
</tr> 

<tr> 
<td>Data3 <img class="one" data-title="Data3" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" /> 
</td> 
</tr> 

    </table></td></tr> 
</table> 
<table class="myTooltipTable"> 
    <tr><td> <span id="test" >test</span></td></tr> 
</table> 

回答

0

如果你總是希望剛剛拿到第一排的Table1Title你可以只訪問它的方法,而不是傳遞它:

function test(data){ 
    alert("test invoked with data: " + data); 

    // This gets the title of the first table's row Table1Title 
    var table1Title = $('img.one').first().attr('data-title'); 
}