将一个表的值复制到另一个表(如何将此js函数转换为jQuery) [英] Copying values of one table to another (how to convert this js function to jQuery)

查看:80
本文介绍了将一个表的值复制到另一个表(如何将此js函数转换为jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个小问题.我想做的是将ID的描述从一个表复制到另一个表.我有一半的javascript,有人可以告诉我如何在jquery中转换此函数.我希望将描述基于ID从第一张表复制到第二张表.在jQuery中使用"contains"完成了此操作,(

I am stuck with a small problem here.. What i am trying to do is copy description of id's from one table to another. I have writter half of the javascript and can anybody tell me how to convert this function in jquery. I want the description copied from the first table based on the id to the second table. Have done this in jquery using 'contains', (Comparing 2 tables column values and copying the next column content to the second table) since there are 1000 table rows, the explorer crashes. Is there a way to simplify it ??... the code is as follows...

当我单击第二张表中的test时,当前的javascript工作正常,但是我希望在页面加载时将该值附加到第二张表中……请帮助

the current javascript works when i click on test in the second table, but i want the value to be appended in the second table on page load... pls help

<table class="reportTabe">
<tr><td>psx-pdu120v1</td><td class="itemname" id="psx-pdu120v1">some description1</td></tr>
<tr><td>psx-pdu120v1</td><td class="itemname" id="psx-pdu120v1">some description1</td></tr>
<tr><td>psx-pdu120v3</td><td class="itemname" id="psx-pdu120v3">some description3</td></tr>
<tr><td>psx-pdu120v4</td><td class="itemname" id="psx-pdu120v4">some description4</td></tr>
<tr><td>psx-pdu120v5</td><td class="itemname" id="psx-pdu120v5">some description5</td></tr>
<tr><td>psx-pdu120v6</td><td class="itemname" id="psx-pdu120v6">some description6</td></tr>
<tr><td>psx-pdu120v7</td><td class="itemname" id="psx-pdu120v7">some description7</td></tr>
<tr><td>psx-pdu120v8</td><td class="itemname" id="psx-pdu120v8">some description8</td></tr>
<tr><td>psx-pdu120v9</td><td class="itemname" id="psx-pdu120v9">some description9</td></tr>
</table>

<table class="data">
<tr><td class="whipItem">psx-pdu120v1</td><td onClick="Javascript:alert(document.getElementById('psx-pdu120v1').innerText)";>test</td></tr>
<tr><td class="whipItem">psx-pdu120v3</td><td onClick="Javascript:alert(document.getElementById('psx-pdu120v1').innerText)";>test</td></tr>
<tr><td class="whipItem">psx-pdu120v4</td><td onClick="Javascript:alert(document.getElementById('psx-pdu120v5').innerText)";>test</td></tr>
<tr><td class="whipItem">psx-pdu120v5</td><td Javascript:this.innerText=document.getElementById('psx-pdu120v4').innerText;></td></tr>
<tr><td class="whipItem">psx-pdu120v6</td><td Javascript:this.innerText=document.getElementById('psx-pdu120v5').innerText;></td></tr>
<tr><td class="whipItem">psx-pdu120v7</td><td Javascript:this.innerText=document.getElementById('psx-pdu120v6').innerText;></td></tr>
<tr><td class="whipItem">psx-pdu120v8</td><td Javascript:this.innerText=document.getElementById('psx-pdu120v7').innerText;></td></tr>
<tr><td class="whipItem">psx-pdu120v9</td><td Javascript:this.innerText=document.getElementById('psx-pdu120v8').innerText;></td></tr>
</table>

推荐答案

$(document).ready(function() {
        $('.whipItem', '.data').each(function(index, element) { //for each whipItem in the data table
            var name = $(element).text(); //get the text value
            var desc = $(".itemname[id='" + name + "']").text(); //get the description whose id matches the name in the report table.
            $(element).next().text(desc); //change the value of the next td to the description.
        });
    });

这篇关于将一个表的值复制到另一个表(如何将此js函数转换为jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆