添加按钮和回调funcktion来复制来自...的信息

时间:2017-03-22 09:14:36

标签: javascript jquery html autodesk-navisworks

我有一个由软件(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>代码
  • 后添加一个按钮
  • 附加一个将收集

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

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

有人可以给我一个起点去看吗?我是jQuery的新手。

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

&#13;
&#13;
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);
}
&#13;
<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>
&#13;
&#13;
&#13;