开发者

adding unique class for new div

I want add a unique class for each new div after input, how is it in my code?

Add class for this: <div class="thing"></div>

DEMO: http://jsfiddle.net/wAwyR/2/ => please in here(field) typing a number for adding new input.

function unique() {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

    return text;
}

$('input').live("keyup", function () {
    $('.lee').empty();
    var $val = $(this).val();
    for (var i = 0; i < $val; i++) {
        $('.lee').append('<input type="t开发者_StackOverflowext" name="hi" class="">div class="thing"></div>');
        $('input[hi]').next('div').attr('class', unique())
    }
});


var increment = 0;

function unique() {
    return "u" + increment++;
}

can't that work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜