1.模拟Button的点击事件
<html>
< language=\" \">
function clickFirstButton()
{
document.myForm.button1.click();
}
</ >
<form name=\"myForm\">
<input type=\"button\"
value=\"Display alert box\"
name=\"button1\"
=\"console.log(\'You clicked the first button.\')\"><br>
<input type=\"button\"
value=\"Call on button 1\"
name=\"button2\"
=\"clickFirstButton()\">
</form>
</html>
2.为button按钮添加焦点
<html>
<head>
< language=\" \">
function removeFocus()
{
document.myForm.button2.blur();
}
</ >
</head>
<body>
<form name=\"myForm\">
<input type=\"button\"
value=\"I hold my focus after a click\"
name=\"button1\"><br>
<input type=\"button\"
value=\"I can not hold my focus after a click\"
name=\"button2\"
=\"removeFocus()\">
</form>
</body>
</html>
3.更改button按钮的文本值
<!DOCTYPE html>
<html>
<head>
< type=\'text/ \'
src=\'/js/lib/mootools-core-1.4.5-nocompat.js\'></ >
<style type=\'text/css\'>
button {
width: 6em
}
button:hover span {
display: none
}
button:hover:before {
content: \"Reply!\"
}
</style>
</head>
<body>
<button>
<span>3 replies</span>
</button>
</body>
</html>
4.buuton按钮的 事件实例
<html>
<form name=\"myForm\">
<input type=\"button\"
value=\"Big Button\"
name=\"myButton\"
=\"console.log(\'MouseUp event occured\')\">
</form>
</html>
5.获得Button NAME属性
<html>
<form name=\"myForm\">
<input type=\"button\"
value=\"Press here to see the name of this button\"
name=\"myBigButton\"
=\"displayButtonName()\">
<input type=\"text\"
name=\"textBox\">
</form>
< language=\" \">
function displayButtonName()<
{
document.myForm.textBox.value=document.myForm.myBigButton.name;
}
</ >
</html>
6.禁用和启用button按钮
<html>
<body>
< >
function function1() {
document.all.myButton.disabled = true;
}
function function2() {
document.all.myButton.disabled = false;
}
</ >
<input id=\"myButton\" type=\"button\" value=\"Disable\" =\"function1();\">
<input type=\"button\" value=\"Enable\" =\"function2();\">
</body>
</html>
7.获取buuton所在的form表单
<html>
<body>
<form name=\"myForm\">
<input type=\"button\"
value=\"Big Button\"
name=\"myButton\">
</form>
< language=\" \">
if(document.myForm.myButton.form == document.myForm)
console.log(\"myButton\'s form property is equal to myForm \");
else
console.log(\"myButton\'s form property is NOT equal to myForm \");
</ >
</body>
</html> 继续阅读与本文标签相同的文章
上一篇 :
css实现鼠标悬停button文本改变
-
你的脸还要吗?机器人公司全球买人脸肖像权,报酬高达百万
2026-05-15栏目: 教程
-
今日分享!组合多种不同格式的文件为单个PDF!
2026-05-15栏目: 教程
-
华为欢迎德国为5G供应商提供公平竞争环境
2026-05-15栏目: 教程
-
绑了银行卡的微信,一定要删除这个记录,不然钱被转了都不知道
2026-05-15栏目: 教程
-
Python基础知识储备,List集合基本操作大盘点
2026-05-15栏目: 教程
