所选添加的div可拖动 [英] selected added div be draggable

查看:54
本文介绍了所选添加的div可拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望添加的div可拖动.
我可以通过添加$("div[id^=new-text]:last").draggable();
但这是行不通的.

I want my added div be draggable.
I can do it by adding $("div[id^=new-text]:last").draggable();
But this is not work.

我的完整示例链接

这是代码:

var count=0;
$(function() {
    $(".add-new").click(function() {
        $('.image').append("<div id='new-text_"+count+"' contenteditable>Edit me</div>");
        count++;
    });

    $('#writable').keydown(function() {
        var writable_value = $('#writable').val();
        $("div[id^=new-text]:last").text(writable_value);
    });

    /*change font family*/
    $("#fs").change(function() {
        //alert($(this).val());
        $("div[id^=new-text]:last").css("font-family", $(this).val());
    });

    $("#fc").change(function() {
        //alert($(this).val());
        $("div[id^=new-text]:last").css("color", $(this).val());
    });

    /* change font size */
    $("#size").change(function() {
        $("div[id^=new-text]:last").css("font-size", $(this).val() + "px");
    });

    $("div[id^=new-text]:last").draggable();
})

推荐答案

如果您要拖动任何添加的文本.您将寻找以下内容:

If you want any of the added text to be draggable. You will be looking for the following:

$("div[id^=new-text]").draggable();

您当前拥有的不是这个:

Instead of this what you have currently:

$("div[id^=new-text]:last").draggable();

您只选择了最后一个新文本元素,因此您需要选择所有id包含新文本的元素.

You was only picking the last new-text element, so you need to select all the elements with the id containing new-text.

这篇关于所选添加的div可拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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