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

How to change the display position of a control in javascript

coldplay.xixi
coldplay.xixi Original
2021-04-08 15:38:39 4880browse

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数值

2. Use js to change the class of the element

Written style

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

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样式

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!

Statement:
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