使用JQuery动态添加Div [英] Add Div Dynamically using JQuery
本文介绍了使用JQuery动态添加Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定这是否是最好的选择..但我想要的是,当用户点击一个按钮时,它会添加另一个div或li。
我将允许用户上传文件,但是会有多个文件。我希望用户能够点击一个按钮,并点击一个新的< div>
或< li>
是用预定义的代码生成的。这是可能的吗?
这是一个小提琴..
解决方案
点击(函数(){
$(< li />)。html(item)。appendTo(您可以使用创建元素, $(< tag />)
并设置属性,添加类等等。然后追加你想要的地方。I'm not sure if this would be the best option.. But I want the option that when the user clicks a button, it will add another div or li.
I am going to allow users to upload documents, but multiple ones. I'd like to for the user to be able to click a button, and a new
<div>
or<li>
is generated with predefined code. Is this possible?Here's a fiddle..
解决方案Your example updated on jsFiddle
$("input[type=submit]").click(function(){ $("<li />").html("item").appendTo("ul"); })
You can create elements using
$("<tag />")
and set attributes, add classes and so on. Then append where you want.这篇关于使用JQuery动态添加Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文