频道栏目
首页 > 资讯 > JS 实例 > 正文

Button 对象

16-01-27        来源:[db:作者]  
收藏   我要投稿
当点击完button不可用
源代码
<!DOCTYPE html>
<html>
<body>

<form>
Buttons:
<input type="button" id="firstbtn" value="OK">
<input type="button" id="secondbtn" value="OK">
</form>

<p>Click the button below to disable the first button above.</p>

<button onclick="disableElement()">Disable button</button>

<script>

function disableElement()
{
document.getElementById("firstbtn").disabled=true;
}

</script>
</body>
</html>

 

运行结果
返回一个button的name
源代码
<!DOCTYPE html>
<html>
<body>

<button id="button1" name="button1">Click Me!</button>

<p>The name of the button is: 
<script>
document.write(document.getElementById("button1").name);
</script></p>

</body>
</html>

 

运行结果
返回一个button的type
源代码
<!DOCTYPE html>
<html>
<head>
<script>
function alertType()
{
alert(document.getElementById("myButton").type)
}
</script>
</head>
<body>

<button id="myButton" type="button" onclick="alertType()">Click Me!</button>

</body>
</html>

 

运行结果
返回一个button的value
源代码
<!DOCTYPE html>
<html>
<body>

<input type="button" id="button1" value="Click Me!">

<p>The text on the button is: 
<script>
document.write(document.getElementById("button1").value);
</script></p>

</body>
</html>

 

运行结果
返回一个button所属表的ID
源代码
<!DOCTYPE html>
<html>
<body>

<form id="form1">
<button id="button1" type="button">Click me!</button>
</form>

<p>The id of the form containing the button is: 
<script>
document.write(document.getElementById("button1").form.id);
</script></p>

</body>
</html> 

 

运行结果

相关TAG标签
上一篇:Form 对象
下一篇:Base 对象
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站