jquery 之设置表格创建对象

  • 使用jquery来动态创建表格和删除
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

<%@ 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>js的学习</title>
<script type="text/javascript" src="js/jquery-3.0.0.js"></script>
<style type="text/css">
.class1 {
background-color: black;

}
.class2{
background-color: white;

}


</style>
<script type="text/javascript">
//获取函数
$(function (){
var ps =$("p");
//按钮的点击的事件
$("#get").click(function(){

for (var i = 0; i < ps.length; i++) {
//获取内容
console.log($(ps[i]).text())

}

});
//通过jquery获取值val
//点检事件其实就是获取按钮的jQuery的对象或去点击的事件
$("#getv").click(function(){
//获取文本框的对象
$("#v").val("傻B");



});
//获取属性
$("#geta").click(function(){
//获取想要获得属性的对象
//alert($("#v").attr("type"));



});
//s设置属性jquery没有属性全是方法
$("#setAtt").click(function(){
if($(this).text()=="白")
{ //获取当前的属性对象
$(this).text("黑");
$("#b").attr("class","class1");
}else
{
//alert("进啦");
$(this).text("白");
$("#b").attr("class","class2");


}



});
//制作表格
//附加
$("#append").click(function (){
//制作td
var td1=$("<td></td>").text("123");
var td2=$("<td></td>").text("123");
var td3=$("<td></td>").text("123");
var td4=$("<td></td>").text("123");
var td4=$("<td></td>").html("<a href='#' onclick ='delete1(this)'>删除</a>");
var tr =$("<tr></tr>")
tr.append(td1);
tr.append(td2);
tr.append(td3);
tr.append(td4);
$("tbody").append(tr);



});




});
function delete1 (th){
th.parentNode.parentNode.parentNode.removeChild(th.parentNode.parentNode);


}
</script>
</head>
<body id="b">
<p>第1段的内容</p>
<p>第2段的内容</p>
<p>第3段的内容</p>
<p>第4段的内容</p>
<input type="text" id="v">
<button id="get">点击获取内容</button>
<br>
<button id="getv">点击赋予内容</button>
<br>
<button id="geta">点击获取属性</button>
<br>
<button id="setAtt">设置属性</button>


<table border="1" cellspacing="0"><tbody></tbody></table>

<button id="append" >增加表格</button>

</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值