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'].
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!