Home > Web Front-end > Front-end Q&A > How to change the width of td with jquery

How to change the width of td with jquery

WBOY
Release: 2022-06-06 18:24:39
Original
2082 people have browsed it

方法:1、利用“$("td元素")”获取td元素对象;2、利用css方法修改元素的width,语法为“td元素对象.css("width","改变后的宽度");”。css()方法用于设置或返回被选元素的一个或多个样式属性。

How to change the width of td with jquery

本教程操作环境:windows10系统、jquery3.2.1版本、Dell G3电脑。

jquery怎么改变td的width

1、获取td元素对象

语法如下:

$("td元素")
Copy after login

2、css()方法修改width

css() 方法设置或返回被选元素的一个或多个样式属性。

如需返回指定的 CSS 属性的值,请使用如下语法:

css("propertyname");
Copy after login

如需设置指定的 CSS 属性,请使用如下语法:

css("propertyname","value");
Copy after login

示例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("td").css("width","200px");
  });
});
</script>
</head>
<body>
<table border="1">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>
<button>设置 </button>
</body>
</html>
Copy after login

输出结果:

How to change the width of td with jquery

视频教程推荐:jQuery视频教程

The above is the detailed content of How to change the width of td with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template