全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 538|回复: 4

[Windows VPS] js(jquery)问题请教,关于克隆

[复制链接]
发表于 2019-6-18 17:12:50 | 显示全部楼层 |阅读模式
本帖最后由 屮喵 于 2019-6-18 17:27 编辑

现有一个table,里面有一行数据,使用clone复制这行数据,但是复制生成的新数据需要修改id值,现在复制操作已经实现了,但是修改id值不会弄

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style type="text/css">
  5. th{color:red;border:1px solid red;}
  6. td{border:1px solid red;}
  7. </style>
  8. </head>
  9. <body>
  10.         <table>
  11.                 <tr>
  12.                         <th>序号</th>
  13.                         <th>姓名</th>
  14.                         <th>电话</th>
  15.                         <th>操作</th>
  16.                 </tr>
  17.                 <tr>
  18.                         <td id="id-10">01</td>//要修改【id-10】里面的10
  19.                         <td>王尼玛</td>
  20.                         <td>13600002345</td>
  21.                         <td>
  22.                                 <input type="button" value="删除" onclick="Del($(this))" />
  23.                                 <input type="button" value="复制" onclick="Copy($(this))" />
  24.                         </td>
  25.                 </tr>
  26.         </table>
  27.        
  28. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  29. <script type="text/javascript">       
  30. function Del(obj){
  31.         obj.parent().parent().remove();
  32. }

  33. var rand =  Math.floor((Math.random()*100)+10);//生成随机数替换掉上面【id-10】里面的10
  34. alert(rand);
  35. function Copy(obj){
  36.         var tr = obj.parent().parent().clone();
  37.         tr.appendTo(obj.parent().parent().parent());
  38. }//复制对象,但是怎么用随机数rand替换【id-10】里面的10
  39. </script>       
  40. </body>
  41. </html>
复制代码
发表于 2019-6-18 17:26:42 | 显示全部楼层
  1. function Copy(obj){
  2.         var tr = obj.parent().parent().clone();
  3.         tr.children('td:first')[0].id = rand;
  4.         tr.appendTo(obj.parent().parent().parent());
  5. }
复制代码
 楼主| 发表于 2019-6-18 17:29:31 | 显示全部楼层

大佬牛逼,感谢感谢   
发表于 2019-6-18 17:29:36 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2019-6-18 19:49:38 | 显示全部楼层
感觉你连JQuery基本的使用模型都不知道。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-27 00:44 , Processed in 0.058225 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表