Home > Web Front-end > JS Tutorial > How to change the display position of a control in javascript

How to change the display position of a control in javascript

coldplay.xixi
Release: 2023-01-04 09:35:15
Original
5019 people have browsed it

Javascript method to change the display position of the control: 1. Use js to change the style of the control; 2. Use js to change the class of the element, the code is [elem.className='newPosition'].

How to change the display position of a control in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

Javascript method to change the display position of the control:

1. Use js to change the style of the control

var elem=document.getElementById("控件id");//获取控件
  elem.style.position = "absolute";//设置绝对定位(或者相对定位)
  elem.style.left = "50px";//设置left数值
  elem.style.top = "100px";//设置top数值
Copy after login

2. Use js to change the class of the element

Written style

.newPosition{position:absolute;top:50px;left:100px;}
Copy after login

Change the element class (can be bound to an event, or the page is loaded and executed)

var elem=document.getElementById("控件id");//获取控件
elem.className='newPosition';//为空间添加class样式
Copy after login

Related Free learning recommendations: javascript video tutorial

The above is the detailed content of How to change the display position of a control in javascript. 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