将值传递给javascript函数onclick

时间:2014-12-05 16:10:54

标签: javascript jquery html

我想将两个不同表格行值的值传递给javascript函数,点击工具提示数据。

请找小提琴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>

1 个答案:

答案 0 :(得分: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');
}
相关问题