惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
F
Fortinet All Blogs
I
InfoQ
Jina AI
Jina AI
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
雷峰网
雷峰网
B
Blog RSS Feed
C
Check Point Blog
Y
Y Combinator Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
Engineering at Meta
Engineering at Meta
G
Google Developers Blog

博客园 - Xia.CJ

C# 委托 node.js中连接mongodb(Please ensure that you set the default write...)解决办法 node.js api解读之file system模块 Node.js小技巧 在windows上安装新版node.js-node.js学习笔记 Asp.Net MVC部暑托管服务器iis7提示403错误解决方法 mvc3中使用unobtrusive时,ajax更新加载页面后验证失效解决方法 ashx中使用HttpContext.Current.Session ,出现未将对象引用设置到实例上 搜索引擎(google/百度)高级指令 在mvc3中使用uploadify上传组件User.isAuthenticated等于false解决方法 MVC中用Html.RenderPartial还是Html.RenderAction或者Html.Partial-Xia.CJ 在_Layout使用Html.RenderAction的问题-MVC3(Razor)问题 无法删除此对象,因为未在 ObjectStateManager 中找到它-entity framework删除时 Javascript数组(array)操作 序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用 entity framework(EF)_code first复杂类型(Complex Types)问题 entity framework多对多关系查询 JQuery获取checkbox值,checkbox全选,操作checkbox JQuery操作Select
JQuery动态创建DOM、表单
Xia.CJ · 2011-08-09 · via 博客园 - Xia.CJ

JQuery动态创建DOM、表单元素

代码很简单,直接上代码。别忘记引用JQuery包。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>createElement</title>
<style type="text/css">
	.warpper{ border:1px solid red; padding:8px;}
</style>
<script type="text/javascript" language="javascript" src="JavaScript/jquery-1.6.1.min.js" ></script>
<script type="text/javascript" language="javascript">
<!--
///动态创建一个div
$(function(){ 
	$('<div />',{
		id:'test',
		text:"this is a div",
		"class":"warpper",
		click:function(){
				var text=$(this).text();
		  		alert(text);
		  	  }
	}).appendTo("body");
});

//创建input:text
$(function(){ 
	$('<input />',{
		type:"text",
		val:"input text somethings...",
		name:"userName"
	}).appendTo("body");		
});

//创建input select
$(function(){ 
	var slt=$('<select />',{name:"country" });
	$('<option />',{
			val:"0",
			text:"请选择"
	}).appendTo(slt);
		$('<option>',{
			val:"CN",
			text:"China",
			selected:"selected"
	}).appendTo(slt);
	$("body").append(slt);
});


//创建radio
$(function(){ 
	$('<input />',{
			type:"radio",
			name:"rdo",
			checked:"checked",
			val:"男"
	 }).appendTo("body");
	 $('<label>',{
		 	text:"男",
		 }).appendTo("body");	
	$('<input />',{
			type:"radio",
			name:"rdo",
			val:"女"
	 }).appendTo("body");
	 $('<label>',{
		 	text:"女"
		 }).appendTo("body");		 
});

//creat checkbox
$(function(){ 
	$('<input />',{
			 type:"checkbox",
	 	 	 name:"cbox",
			 val:"1",
			 checked:"checked"
		 }).appendTo("body");
});
$(function(){ 
	$('<input />',{
			type:"file",
			name:"myfile"	
	 }).appendTo("body");
});
//-->
</script>
</head>

<body>
<form>
</body>
</html>