JQuery克隆< select>元件 [英] JQuery clone <select> element

查看:134
本文介绍了JQuery克隆< select>元件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想克隆一个< select>输入为HTML格式,使用JQuery。

我不知道该怎么去做,所以我想在这里问一下。

I want to clone a <select> input in HTML using JQuery.
I'm not sure how to go about it, so thought I'd ask here.

特别感兴趣以最好的方式将它写回到文档中。

Particularly interested in the best way to write it back into the document as well.

我的select元素如下所示:

My select element looks like this:

<select id="options">
    <option value="1">Opt 1</option>
    <option value="2">Opt 2</option>
    <option value="3">Opt 3</option>
</select>

谢谢。

Thanks.

推荐答案

请参阅: http://api.jquery.com/clone/

$('select#options').clone().attr('id', 'newOptions').appendTo('.blah');

appendTo(...)只是插入克隆元素的一种方法。其他方法可以在这里找到: http://api.jquery.com/category/manipulation/

appendTo(...) is only one way to insert the cloned elements. Other methods can be found here: http://api.jquery.com/category/manipulation/

这篇关于JQuery克隆&lt; select&gt;元件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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