0

我有以下由软件(Navisworks)生成的 HTML 报告:

<tr class="contentRow">
	<td colspan="2" class="contentCell">
		<a target="_blank" href="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg ">
			<img border="0" width="95" height="95" src="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg">
		</a>
		<!-- HERE I WOULD LIKE TO INSERT A BUTTON -->
	</td>
	<td colspan="2" class="contentCell">Clash1</td>
	<!-- more td !-->
	<td class="item1Content">
		<i>Element ID</i>:
		509894
	</td>
	<!-- more contet as td !-->
	<td class="item2Content"><i>Element ID</i>:
		576096
	</td>
	<!-- more contet as td !-->
</tr>

<tr class="contentRow">
	<td colspan="2" class="contentCell">
		<a target="_blank" href="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg ">
			<img border="0" width="95" height="95" src="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg">
		</a>
		<!-- HERE I WOULD LIKE TO INSERT A BUTTON -->
	</td>
	<td colspan="2" class="contentCell">Clash2</td>
	<!-- more td !-->
	<td class="item1Content">
		<i>Element ID</i>:
		509894
	</td>
	<!-- more contet as td !-->
	<td class="item2Content"><i>Element ID</i>:
		576096
	</td>
	<!-- more contet as td !-->
</tr>

我想做以下事情:

  • <a></a>在每个标签后添加一个 Button
  • 附加一个将收集 ID 的函数

    <td class="item1Content">
        <i>Element ID</i>:
        509894
    </td>
    

    和身份证

    <td class="item2Content"><i>Element ID</i>:
        576096
    </td>
    
  • 并将其复制到剪贴板

有人可以给我一个起点吗?我对 jQuery 很陌生。

4

1 回答 1

0

试试下面的代码:

var rows = $('#testTable > tbody > tr');
$.each(rows, function(index, value){
    $(`<input type="button" value="Get Info"/ onclick="getInfo(this)">`).appendTo($(this).find('td:first-child'))
});

function getInfo(that){
    var id1 = $(that).parent().parent().find('.item1Content')[0].innerText;
    var id2 = $(that).parent().parent().find('.item2Content')[0].innerText;
    console.log(id1);
    console.log(id2);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="testTable">
    <tr class="contentRow">
        <td colspan="2" class="contentCell">
            <a target="_blank" href="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg ">
                <img border="0" width="95" height="95" src="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg">
            </a>
            <!-- HERE I WOULD LIKE TO INSERT A BUTTON -->
        </td>
        <td colspan="2" class="contentCell">Clash1</td>
        <!-- more td !-->
        <td class="item1Content">
        <i>Element ID</i>:
            509894-1
        </td>
        <!-- more contet as td !-->
        <td class="item2Content"><i>Element ID</i>:
            576096-2
        </td>
        <!-- more contet as td !-->
    </tr>

    <tr class="contentRow">
        <td colspan="2" class="contentCell">
            <a target="_blank" href="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg ">
                <img border="0" width="95" height="95" src="100+200_WS-U2-U1_default-Hard_files\cd000001.jpg">
            </a>
            <!-- HERE I WOULD LIKE TO INSERT A BUTTON -->
        </td>
        <td colspan="2" class="contentCell">Clash2</td>
        <!-- more td !-->
        <td class="item1Content">
        <i>Element ID</i>:
            509894-3
        </td>
        <!-- more contet as td !-->
        <td class="item2Content"><i>Element ID</i>:
            576096-4
        </td>
        <!-- more contet as td !-->
    </tr>
</table>

于 2017-03-22T10:12:03.917 回答