更改克隆对象内的 html 对象

发布于 2024-09-14 12:50:59 字数 911 浏览 1 评论 0原文

假设我有这样的 tr :

<tr id="file" >
            <td width="510"><div align="right"><span class="star"> *</span>
                <input type="text" name="title" style="width:500px;direction:ltr"  />
            </div></td>
            <td width="156" nowrap="nowrap"><div align="right">file </div></td>
          </tr>

我必须在页面底部链接,让我做一些操作我的 js 代码是:

$(function(){

        $(".add").click(function(e){
            e.preventDefault();
            var copy =$('#file').clone().removeAttr('id').insertBefore($('.submit')) ;


            console.log('add called') ;
        });

        $('.remove').click(function(e){
            e.preventDefault();
            console.log('remove called ');
        });     


    }) ;

如果用户首先在第一个输入中输入一些文本,我在副本中有相同的文本,我想清除输入在我创建副本之后。坦克

supose i have tr like this :

<tr id="file" >
            <td width="510"><div align="right"><span class="star"> *</span>
                <input type="text" name="title" style="width:500px;direction:ltr"  />
            </div></td>
            <td width="156" nowrap="nowrap"><div align="right">file </div></td>
          </tr>

and i have to link at bottom of page that let me do some action my js code is :

$(function(){

        $(".add").click(function(e){
            e.preventDefault();
            var copy =$('#file').clone().removeAttr('id').insertBefore($('.submit')) ;


            console.log('add called') ;
        });

        $('.remove').click(function(e){
            e.preventDefault();
            console.log('remove called ');
        });     


    }) ;

if the user first input some text in first input i have the same text in copy , i want to clear input after i create copy . tanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2024-09-21 12:51:00

您可以使用 .find().val('') 在链中清除值,像这样:

$('#file').clone().removeAttr('id').insertBefore('.submit')
                  .find('input').val('');

This search inside克隆元素以清除它找到的 。如果稍后需要更具体,可以使用 .find('input[name=title]')。如果您需要 copy 引用,只需添加 .end()< /code>.val('') 调用,以便您引用 而不是它的

You can use .find() and .val('') in the chain to clear the value, like this:

$('#file').clone().removeAttr('id').insertBefore('.submit')
                  .find('input').val('');

This searches inside the cloned element to clear the <input> it finds. If you need to be more specific later, you can use .find('input[name=title]'). If you need that copy reference, just add a .end() after the .val('') call so you're referencing the <tr> and not the <input> with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文