加入收藏 | 设为首页 | 会员中心 | 我要投稿 泉州站长网 (https://www.0595zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

jQuery中如何修改td的高?教你两个办法

发布时间:2022-02-08 15:02:09 所属栏目:语言 来源:互联网
导读:jQuery中如何修改td的高?想要修改td的高,也就是修改元素的值,这里给大家分享两个方法,一种是使用attr()方法,另一种是使用css()方法,实现代码如下,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧! 本教程操作环境:windows7系统、jquery1.1
       jQuery中如何修改td的高?想要修改td的高,也就是修改元素的值,这里给大家分享两个方法,一种是使用attr()方法,另一种是使用css()方法,实现代码如下,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
   
      本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
 
      jQuery怎么修改td的高
 
      1、使用attr()方法
 
      attr() 方法可设置被选元素的属性值。
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("td").attr("style","height: 50px;");
});
});
</script>
 
</head>
<body>
<table border="1">
<caption>人物信息</caption>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
<tr>
<td>Peter</td>
<td>20</td>
</tr>
<tr>
<td>Lois</td>
<td>20</td>
</tr>
</table><br />
<button>修改td的高</button>
</body>
</html>
 
 
    2、使用css()方法
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("td").css("height","50px");
});
});
</script>
 
</head>
<body>
<table border="1">
<caption>人物信息</caption>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
<tr>
<td>Peter</td>
<td>20</td>
</tr>
<tr>
<td>Lois</td>
<td>20</td>
</tr>
</table><br />
<button>修改td的高</button>
</body>
</html>

(编辑:泉州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读