1、事件分配方式
标签分配onclick事件
<script>
function changetext(id)
{
id.innerHTML="谢谢!";
}
</script>
</head>
<body>
function changetext(id)
{
id.innerHTML="谢谢!";
}
</script>
</head>
<body>
<h1 οnclick="changetext(this)">请点击该文本</h1>
</body>
用dom来分配事件
document.getElementById("myBtn").οnclick=function(){displayDate()};
2、mouseover()和mouseout()
onmousedown 和 onmouseup
3、(1)onload加载完成显示提示
(2)onfocus获得聚焦时触发事件
<script>
function myFunction(x)
{
x.style.background="yellow";
function myFunction(x)
{
x.style.background="yellow";
}
4、要删除元素就得获得父类
parent.removeChild(child);
5、循环遍历对象 "person" 的属性
</script>
</head>
<body>
<body>
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
<button οnclick="myFunction()">点击这里</button>
<p id="demo"></p>
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
<button οnclick="myFunction()">点击这里</button>
<p id="demo"></p>
<script>
function myFunction()
{
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age:56};
function myFunction()
{
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age:56};
for (x in person)
{
txt=txt + person[x];
}
{
txt=txt + person[x];
}
document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
}
</script>
</body>
7、使用 match() 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。
str.match(person[1]);
</script>
</head>
<body>
请输入英文字符:<input type="text" οnfοcus="myFunction(this)">
替换字符串内容
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))
var str="Visit Microsoft!"
document.write(str.replace(/Microsoft/,"W3School"))
<p>当输入字段获得焦点时,会触发改变背景颜色的函数。</p>
</body>
8、
RegExp 对象用于规定在文本中检索的内容。
用new创建RegExp对象
var patt1=new RegExp("e");
RegExp的方法:text()用于检索返回一个布尔值
RegExp的方法:text()用于检索返回一个布尔值
exce用于检索返回检索内容
compile用于改变检索内容
9、警告alert 确认confirm 提示prompt三个方法的使用
οnclick='return confirm("确认提交")'
10、js timing 设置多长时间执行
计时 例:
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}
var t
function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}