繁体   English   中英

将值传递给javascript函数onclick

[英]pass values to javascript function onclick

我想将两个不同表的行值的值传递给工具提示数据上的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>

如果您始终只想获取第一行的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');
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM