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

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


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

在此处编辑div的html:

<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选择器将起作用。

09-30 19:39
查看更多