jquery怎么设置div大小

使用jquery设置div标签大小的方法:1.新建html项目,引入jquery;2.创建div标签,设置id属性;3.添加button按钮,绑定onclick点击事件;4.通过id获取标签对象,使用width()和height()方法设置标签大小;

具体步骤如下:

1.首先,新建一个html项目,并在项目中引入jquery;

<script type="text/javascript" src="/static/jquery-2.1.4.min.js"></script>


2.引入jquery后,在项目中创建一个div标签,并设置id属性,用于测试;



<div id="btn">测试标签</div>


3.div标签好后,添加一个button按钮,并绑定onclick点击事件,用于点击设置大小;

<button onClick="set()"><button>


4.最后,按钮添加好后,在点击事件中通过id获取标签对象,在使用width()和height()方法即可设置div标签的大小;

function set(){

$("#btn").width('50px').height('100px');

}


Both comments and pings are currently closed.

Comments are closed.

Powered by KingAbc | 粤ICP备16106647号-2 | Loading Time‌ 0.526