方法:1、利用“$("td元素")”獲取td元素對象;2、利用css方法修改元素的width,語法為“td元素對象.css("width","改變后的寬度");”。css()方法用于設(shè)置或返回被選元素的一個或多個樣式屬性。
本教程操作環(huán)境:windows10系統(tǒng)、jquery3.2.1版本、Dell G3電腦。
jquery怎么改變td的width
1、獲取td元素對象
語法如下:
$("td元素")
2、css()方法修改width
css() 方法設(shè)置或返回被選元素的一個或多個樣式屬性。
如需返回指定的 CSS 屬性的值,請使用如下語法:
css("propertyname");
如需設(shè)置指定的 CSS 屬性,請使用如下語法:
css("propertyname","value");
示例如下:
<!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>設(shè)置 </button> </body> </html>
輸出結(jié)果:
視頻教程推薦:jQuery視頻教程