用jquery动态创建元素

来源:互联网 发布:linux date 格式化 编辑:程序博客网 时间:2024/05/17 19:58
<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title><script type="text/javascript" src="jquery/jquery-1.11.1.js"></script><script type="text/javascript">$(function(){$("#btn").click(function(){var file = $("<input type='file' id='file' />");var btn = $(" <input type='button' value='删除' />");var br =$("<br>" );//单独把file 和btn 和br 拿出来目的就为了 容易删除,其实也可以用循环,不过我感觉有点麻烦,这样简单,一目了然 $("#div1").append(file).append(btn).append(br); $(btn).click(function(){  file.remove();  br.remove();  btn.remove(); });});});</script></head><body><input type="button" id="btn" value="增加"><br><div id="div1"></div></body></html>

0 0
原创粉丝点击