< html>
< head>
< title> 点击按钮使其自动移动</ title>
< script>
var interval
function chenge ( )
{
var a1 = document. getElementById ( "egg" )
var i = 0
interval = setInterval ( function ( ) {
a1. style. marginLeft= i
if ( i< 300 )
{
i= i+ 3
console. log ( i) ;
}
else {
clearInterval ( interval)
}
} , 50 ) ;
}
function x ( ) {
var ass = document. getElementsByClassName ( "nba" )
var i = 0
for ( i= 0 ; i< ass. length; i++ )
{
ass[ i] . innerText = "123"
}
}
function end ( ) {
clearInterval ( interval)
}
</ script>
</ head>
< body>
< div id = " egg" style =" background-color : blue; width : 400px; height : 400px; " > </ div>
< input type = " button" value = " 开始" onclick = " chenge(),x()" />
< input type = " button" value = " 结束" onclick = " end()" />
< p class = " nba" > </ p>
< p class = " nba" > 你好</ p>
< p class = " nba" > 你好</ p>
< p class = " nba" > 你好</ p>
< p class = " nba" > 你好</ p>
< p class = " nba" > 你好</ p>
</ div>
</ body>
</ html>
< html>
< head>
< title> 弹出窗口,以及基本的点击按钮改变</ title>
< Script src = " script.js" > </ Script>
</ head>
< body>
< input type = " button" value = " 确定" onclick = " alert(' Hello World!' )" />
<p id = a1> 撒大大大叔</ p>
< input type = " button" value = " 修改" onclick = " change()" />
<img src="0.gif" id="a2"οnclick="change1()">
< input type = " button" value = " 熄灭" onclick = " change2()" >
</ body>
</ html>
< html>
< head>
< title> huoqu</ title>
< style type = " text/css" >
.div1 {
width : 300;
height : 300;
background-color : rgb ( 24, 214, 88) ;
border-radius : 30%;
position : absolute;
}
</ style>
< script>
var oldc_x;
var old_off_x;
var oldc_y;
var old_off_y;
var flag = false
function down ( ) {
var x = document. getElementById ( "a1" )
flag = true
x. style. backgroundColor = "red"
oldc_x = window. event. clientX;
oldc_y = window. event. clientY;
old_off_x = x. offsetLeft;
old_off_y = x. offsetTop;
console. log ( "falg:" + flag)
}
function move ( ) {
var x = document. getElementById ( "a1" )
if ( flag) {
x. style. backgroundColor = "black"
var newc_x = window. event. clientX;
x. style. marginLeft = old_off_x + newc_x - oldc_x + "px" ;
var newc_y = window. event. clientY;
x. style. marginTop = old_off_y + newc_y - oldc_y + "px" ;
console. log ( "Top:" + x. style. marginTop)
console. log ( "Left:" + x. style. marginLeft)
}
}
function up ( ) {
var x = document. getElementById ( "a1" )
flag = false
x. style. backgroundColor = "blue"
console. log ( "!!!falg:" + flag)
}
document. onkeydown = function ( event) {
var box = document. getElementById ( "a1" )
var e = event || window. event || arguments. callee. caller. arguments[ 0 ] ;
if ( e&& e. keyCode == 38 ) {
box. style. top = box. offsetTop - 2 ;
}
else if ( e&& e. keyCode == 37 ) {
box. style. left = box. offsetLeft - 2 ;
}
else if ( e&& e. keyCode == 40 ) {
box. style. top = box. offsetTop + 2 ;
}
else if ( e&& e. keyCode == 39 ) {
box. style. left = box. offsetLeft + 2 ;
}
}
</ script>
</ head>
< body onmousemove = " move()" >
< div id = " a1" class = " div1" onmousedown = " down()" onmouseup = " up()" >
</ div>
</ body>
</ html>