jQuery将td onclick值传递到其他表
jQuery Pass td onclick value to other table
我试图找到这个问题的解决方案,但我找不到合适的文章
<div class="panel ui-widget-content" id="invoiceList">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Invoices</span></h2>
<table cellspacing='0' id='header' class="ui-widget">
<tr>
<th>Invoice Number</th>
<th>Invoice Total</th>
</tr>
<tr>
<td><a href="#" >INV-Error_Test1</a></td>
<td>22.000000 USD</td>
</tr>
<tr>
td><a href="#" >INV-Error_Test2</a></td>
<td>22.000000 USD</td>
</tr>
</table>
</div>
<div class='panel ui-widget-content' id="invoiceErrors">
<h2>Select a Invoice from the left to view Error Details</h2>
<div class='panel ui-widget-content' id="invoiceHeaders">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Invoice Headers</span></h2>
<table class="ui-widget">
<tr>
<th>Invoice Number</th>
<th>Matter Number</th>
<th>Invoice Total</th>
<th>Invoice Tax Total</th>
<th>Invoice Net Total</th>
</tr>
<tr>
<td><%= invoiceNumber%></td>
<td>CC_MAT_1221</td>
<td>22.000000 USD</td>
<td>22.000000 USD</td>
<td>22.000000 USD</td>
</tr>
<td class = 'error'>File Error : The file does not contain any record delimiters or is in an unsupported format</td>
</table>
</div>
<div class='panel ui-widget-content' id="invoiceLines">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Invoice Line Items</span></h2>
<table class="ui-widget">
<tr>
<th>Line Item Number</th>
<th>Line Item Date</th>
<th>Unit Cost</th>
<th>Number of Units</th>
<th>Line Item Total</th>
<th>Task Code</th>
<th>Expense Code</th>
<th>Timekeeper ID</th>
<th>Line Item Description</th>
</tr>
<tr>
<td>2</td>
<td>20150304</td>
<td>2</td>
<td>2</td>
<td>6</td>
<td></td>
<td>E2</td>
<td></td>
<td></td>
</tr>
<td class='error'><%= invoiceNumber%> Line : 2 Invoice does not foot Reported = (22.0)Calculated (18.0)</td>
<tr>
<td>3</td>
<td>20150306</td>
<td>3</td>
<td>3</td>
<td>12</td>
<td>T3</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
</div>
这是jsfiddle链接http://jsfiddle.net/5n62md3m/
我能够从invoiceList
div获得发票编号,如下所示
$("#invoiceList a").click(function (e) {
console.log('invoice --->'+$(this).text());
});
但我不确定如何在invoiceErrors
div 中将其发送到invoiceNumber
有人能帮我吗?
更新答案
更好的是,多亏了其中一条注释,给单元格一个ID,例如"#invoice number error",然后直接用jQuery针对它,不需要.find(),这样一切都会更快。
aka:
$("#invoiceList").find('a').click(function (e) {
var invoiceNumber = $(this).text();
$('#invoice-number-error').text(invoiceNumber);
});
旧答案
我建议给表单元格类,我更新了你的文件以反映一个变化:
我在#invoiceErrors下的单元格中添加了类"发票编号"。然后我更新了你的功能,看起来像这样:
$("#invoiceList").find('a').click(function (e) {
var invoiceNumber = $(this).text();
$('#invoiceErrors').find('.invoice-number').text(invoiceNumber);
});
给您的表一个类似mytable
的id,然后执行:
$("#mytable td").eq(0).html( $(this).text() );
工作jsFiddle
相关文章:
- 如何将输入范围的值传递给JS中的变量
- 如何将值传递给wicket中的javascript函数
- 将值传递给jquery创建的输入字段
- 需要将select标记选项值传递给ajax函数
- 使用Ajax将PHP值传递给javascript
- 将javascript值传递给PHP
- 将javascript值传递给php是正确的方法
- 将不属于表单的HTML页面中的值传递给php页面
- Angular,将文本框的动态值传给控制器
- 在key up函数上将文本框值传递给javascript
- 可以't使用ajax调用将值传递给Web服务
- 如何在同一页面上使用windows.location.href将js值传递给php时停止刷新页面
- 有没有办法将其他参数传递给 scrollTarget 回调函数
- 多个单选按钮,需要将选定的值传递给javascript
- 将 MSSQL 表值传递给 javascript
- 如何将 HTML 文档作为起始值传递给 CodeMirror
- 如何将数据存储值传递给javascript?我需要从gae数据存储中获取数据,并需要传递javascript
- 将索引值传递给javascript命名空间数组
- 将文本框值传递给javascript函数
- 如何将PHP值传递给Javascript并重定向到其他页面