简体   繁体   中英

pass values to javascript function onclick

I want to pass values of two different table's row values to the javascript function onclick on the tooltip data.

Please find the fiddle http://jsfiddle.net/0w9yo8x6/34/

Below is the sample code:

<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>

If you always want to just get the first row's Table1Title you could just access it in the method instead of passing it:

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');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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