大家都知道,同一个HTML页面中,不宜出现1个以上相同名称的id。但有时候需要使用jQuery框架的clone()来复制相同内容(附带样式),假如是使用了id号的获取方式,即$(‘#***’) 那么复制后得到新的内容也会把id号复制过来了,这时候就会出现一个页面出现2个或多个相同的id,比如:

<span style="font-family:SimSun;font-size:18px;">$('#single').click(function(){
$('#single-answer').clone(true).appendTo('#single-answer-null').show();
});
</span>

这时不妨添加一个变量来动态更改id的值,如:

 <span style="font-family:SimSun;font-size:18px;">var oId = 1;
$('#single').click(function(){
$('#single-answer').clone(true).attr('id','single-answer'+oId).appendTo('#single-answer-null').show();
oId += 1;
});
</span>

这样就使得一个页面不会出现2个或多个相同的id名,保持了id的一致性。

在使用clone()时id保持一致的更多相关文章

  1. 触发器修改后保存之前的数据 表中插入数据时ID自动增长

    create or replace trigger t before update on test5 for each rowbegin insert into test55 values (:old ...

  2. git clone时出现 error:inflate:data stream error(incorrect data check)

    git clone时出现 error:inflate:data stream error(incorrect data check) fatal:serrious inflate inconsiste ...

  3. idea在使用git clone 时出现Filename too long

    idea在使用git clone 时出现Filename too long的报错信息,使用如下命令就可以解决该问题:在 git bash命令模式下,运行命令 git config --global c ...

  4. git clone时加上--depth 1

    当项目过大时,git clone时会出现error: RPC failed; HTTP curl The requested URL returned error: Gateway Time-out的 ...

  5. git clone 时注意点

    环境: 在公司访问外网需要设置代理,另外,在公司局域网内架设了一台 GIT 服务器. 在使用 git clone 时,不能设置成 git 使用代理: git config --global http. ...

  6. Git clone时出现fatal:the remote end hung up unexpectedly

    以HTTPS方式进行git clone时出现如下错误: 方法1:增大缓存 git config http.postBuffer 524288000 尝试无效: 方法2:配置git的最低速度和最低速度时 ...

  7. git clone时,报403错误,完美解决方案

    首先命令行操作结果如下: root@zhiren-PowerEdge-T110-II:/zrun# git clone https://git.coding.net/xxxxxxxx/xxxx.git ...

  8. 创建触发器在表中播入数据时ID自动增长

    ),age )) create or replace trigger gger_tt before insert on ttt for each row when (new.id is null) b ...

  9. 使用windows 命令行执行Git clone时出现Host key error

    由于是在java中执行cmd命令调用git clone,导致git读取不到用户的ssh key,需要设置环境变量Home为正确的用户路径: cmd /c set HOME=C:/Users/你的用户名 ...

随机推荐

  1. Entity Framework Tutorial Basics(19):Change Tracking

    Change Tracking in Entity Framework: Here, you will learn how entity framework tracks changes on ent ...

  2. Python学习笔记--2--面向对象编程

    面向对象 类和装饰器@ #coding=gbk class student: def __init__(self,name,grand):#初始化构造函数,self相当于java中的this,相当于一 ...

  3. Spring JDBCTemplate配置使用

    一.开发环境 Windows 10 IntelliJ IDEA 2016.1 旗舰版 JDK1.8 二.项目和数据库结构 项目结构: 数据库(MySQL 5.5.39): /* Navicat MyS ...

  4. leetcode mergeKsortedlink

    代码:这个代码是有问题的,问题的产生是map中不能存放相同的值. #include<iostream> #include<vector> #include<cmath&g ...

  5. excel导出工具

    介绍 excel导出工具 整个项目的代码结构如下 com \---utils +---demo # 案例相关 | | ExcelExportApplication.java # springboot启 ...

  6. 【Arcgis for android】程序运行出错原因分析及解决(超详细)

    查看项目下是否有libs文件夹,正常情况下其中应该有 如果没有,在项目上右键 ->arcgis tools->convert to arcgis android project 排除了上述 ...

  7. 怎样创建XML文档

    在程序中,我们怎样创建一个XML文档.下面演示中,Insus.NET在程序创建一个和http://www.cnblogs.com/insus/p/3274220.html 一模一样的XML文档. 可以 ...

  8. AI-Info-Micron-Insight:工业 5.0,伟大的思想将殊途同归

    ylbtech-AI-Info-Micron-Insight:工业 5.0,伟大的思想将殊途同归 1.返回顶部 1. 工业 5.0,伟大的思想将殊途同归 两个头脑比一个好吗?似乎如此,尤其是当其中一个 ...

  9. Oracle PL/SQL编程语法

    --plsql块结构,计算a,b的和 declare a ; b ; c int; begin c:=a+b; dbms_output.put_line(c); end; --%type数据类型,输出 ...

  10. 主要介绍JavaEE中Maven Web 项目的结构及其它几个小问题

    先说下本篇随笔的目录. 1.介绍windows中环境变量Path与ClassPath的区别. 2.可能导致命令行运行javac编译成功,但 java命令 + 所要执行的类的类名 无效的原因. 3.介绍 ...