老师讲的事件都体验了一遍,onchange,onsubmit 不会用

原创 2019-02-03 13:42:25 284
摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>javascript之事件的使用方法</title></head><body><script type="text/

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>javascript之事件的使用方法</title>

</head>

<body>

<script type="text/javascript">

function shijian1(x) {

x.style.background="green"

//为什么我用backgroudcolor就不行呢?老师

}

function shijian2(y) {

y.style.background="red"

}

function shijian3() {

Document.getElementById("a").value="who cares!"

}

function shijian4() {

alert("你确定提交了吗?不好好考虑一下了")

}


</script>

1. onfocus:<input type="text" style="width:800px ;height:50px; border-radius: 200px;font-size: 28px;" onfocus="shijian1(this)" value="我是onfocus,点击这里会变绿哦!不信你试试" onblur="shijian2(this)"> <br><br>

<!-- // value值是框里的提示信息 -->

2. onmouseover:<input type="text" style="width:800px ;height:50px; border-radius: 400px;font-size: 28px;" value="我是onmouseover,鼠标到这里这里会变红哦!不信你试试" onmouseover="shijian2(this)"> <br><br>

3. onmouseup:<input type="text" style="width:800px ;height:50px; border-radius: 400px;font-size: 28px;" value="我是onmouseup,鼠标键抬起,这里这里会变红哦!不信你试试" onmouseup="shijian2(this)"> <br><br>

4.onmouseout:<input type="text" style="width:800px ;height:50px; border-radius: 400px;font-size: 28px;" value="我是onmouseout,当鼠标移开" onmouseover="shijian1(this)"> <br><br>

5.鼠标按下onmousedown:<input type="text" style="width:800px ;height:50px; "onmousedown="shijian1(this)"> <br><br>

6.onclick   <button type='button' onclick="shijian1(this)">点我!</button> <br><br>

7.ondbclick  <button type='button' onclick="shijian2(this)">双击点我!</button> <br><br>

8.onblur 写进第一条了 <br><br>

9.onchange<input type="text" id="a" style="width:800px ;height:50px; "  onchange="shijian3(this)" > <br><br>

<!-- onchange不会用 -->

10.onsubmit   <button type='button' onclick="shijian4(this)">提交!</button> <br><br><br><br>

<!-- 不会用提交功能,还不如用onclick呢是不是? -->

</body>

</html>



批改老师:天蓬老师批改时间:2019-02-03 15:13:52
老师总结:onchange(),这个事件, 因表单元素不同, 表现是不一样的,例如input, 只有失去焦点才会触发,而select就不需要, 只要改变就会触发, 这些规则,只有多做才可以记住,没有其它捷径

发布手记

热门词条