附加和滑动在一起 jQuery
我有这个追加方法,我用它来添加更多输入框,直到有 10 个输入框,这将禁用更多输入框。
i = 0;
$('#add-link').click(function()
{
if(i < 9)
{
$('.insert-links').append('<div class="new-link" name="link[]"><input type="text" /></div>');
i++;
}
if(i == 9)
{
$('#add-link').html('');
}
});
虽然,这样也不错。但是,我想在附加时实现幻灯片,我尝试这样做:
$('.insert-links').append('<div class="new-link" name="link[]"><input type="text" /></div>').slideDown("fast");
这根本不起作用。
I have this append method which I made to add more input boxes until there is 10 of them which will disable into making more.
i = 0;
$('#add-link').click(function()
{
if(i < 9)
{
$('.insert-links').append('<div class="new-link" name="link[]"><input type="text" /></div>');
i++;
}
if(i == 9)
{
$('#add-link').html('');
}
});
Although, it's good. However, I want to implement a slideDown when appended, I've tried doing this:
$('.insert-links').append('<div class="new-link" name="link[]"><input type="text" /></div>').slideDown("fast");
Which doesn't work at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
append()
返回对原始选择器的引用,而不是附加的内容。我想您正在寻找这个:现场演示:
http://jsfiddle.net/ V4SVt/2/
append()
returns a reference to the original selector, not what was appended. I think you are looking for this:Live demo:
http://jsfiddle.net/V4SVt/2/
与 SimpleCoder 的解决方案类似,但仅在一行中使用
appendTo()
:演示:http:// /jsfiddle.net/V4SVt/336/
Like SimpleCoder's solution, but in only one line using
appendTo()
:Demo: http://jsfiddle.net/V4SVt/336/
虽然 SimpleCoder 的解决方案完全有效,但我会这样做:
原因是每个链接输入都会获得第二类形式的 ID,这对于如果您不小心添加了多个需求,并且想要删除某个元素,请选择它们。我还在
add-link
元素上添加了淡出效果,这样用户就不会因为它刚刚消失而感到困惑。当然,这只是个人喜好的问题,但我觉得它更人性化。希望这有帮助。
Although SimpleCoder's solution is perfectly valid, I'd do it like this:
The reason for it would be that each link
input
would get an ID in the form of a second class, which would come very handy for selecting them in case one wants to remove an element, should one accidentally add more than one needs. I have also added a fade out effect on theadd-link
element so the user doesn't get confused that it just disappeared. Of course, it is just a matter of personal taste, but I find it more user-friendly.Hope this helps.