jQuery无法使用其ID克隆元素 [英] jquery can't clone an element using its id

查看:155
本文介绍了jQuery无法使用其ID克隆元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jquery克隆 div ,然后更改其子ID之一并在另一个元素之后添加:

I am trying to clone a div using Jquery,then change one of its children's id and the add after another element:

var s = $('#runwell1').clone().wrap('<div>');
s.find('#tag' + runNum).attr('id', 'tag' + (++runNum));
$('#addrun').before(s.parent().html());

,但是此代码不起作用.有什么问题吗?如何使用ID克隆??

but this code is not working. what is wrong with it ?? how to clone using id ??

编辑,这是div的html:

edit here is the html of the div:

<div class="well well-large RunWell" id="#runwell1">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

    <!-- Form Name -->
    <legend>Run 1</legend>

    <!-- Multiple Radios -->
    <div class="control-group">
        <label class="control-label" for="radios">System :</label>
        <div class="controls">
            <label class="radio" for="radios-0">
                <input type="radio" name="radios" id="radios-0" value="op" checked="checked">
                OPE
            </label>
            <label class="radio" for="radios-1">
                <input type="radio" name="radios" id="radios-1" value="mxwl">
                Maxwell
            </label>
        </div>
    </div>

    <!-- Textarea -->
    <div class="control-group">
        <label class="control-label" for="textarea">Tools :</label>
        <div class="controls">
            <input type="text" class="tags" id="tag1" value="Amsterdam,Washington,Sydney,Beijing" data-role="tagsinput" />
        </div>
        </br>
        <div class="SystemFiles" data-role="collapsible">
            <!-- File Button -->
            <div class="control-group">
                <label class="control-label" for="filebutton">OP  DLIS </label>
                <div class="controls">
                    <input id="filebutton" name="filebutton" class="input-file" type="file">
                </div>
            </div>
        </div>

推荐答案

您的ID中有#.

id="#runwell1" <---here

<div class="well well-large RunWell" id="#runwell1">
                          //-------------^----here

删除标记中的#

,您的ID选择器将起作用.

and your id selector will work..

这篇关于jQuery无法使用其ID克隆元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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