HTML type 属性
定义和用法
对于按钮元素,type 属性指定按钮的类型。
对于输入元素,type 属性指定要显示的 <input> 元素的类型。
对于 embed、link、object、script、source 和 style 元素,type 属性指定 Internet 媒体类型(以前称为 MIME 类型)。
适用于
type 属性可用于以下元素:
元素 | 属性 |
---|---|
<a> | type |
<button> | type |
<embed> | type |
<input> | type |
<link> | type |
<menu> | type |
<object> | type |
<script> | type |
<source> | type |
<style> | type |
实例
Button 实例
两个按钮元素充当一个提交按钮和一个重置按钮(在一个表单中):
<form action="/action_page.php" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit" value="提交">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
亲自试一试 »
Embed 实例
具有指定媒体类型的嵌入式 Flash 动画:
<embed src="helloworld.swf" type="application/vnd.adobe.flash-movie">
亲自试一试 »
Input 实例
具有两种不同输入类型的 HTML 表单; 文本和提交按钮:
<form action="/action_page.php">
Username: <input type="text" name="usrname"><br>
<input type="submit" value="提交">
</form>
亲自试一试 »
Link 实例
在下面的例子中,type属性表明链接的文档是一个外部样式表:
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
</head>
亲自试一试 »
Object 实例
具有指定媒体类型的 <object> 元素:
<object width="400" height="400" data="helloworld.swf" type="application/vnd.adobe.flash-movie"></object>
亲自试一试 »
Script 实例
具有指定类型属性的脚本:
<script type="text/javascript">
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
亲自试一试 »
Source 实例
type 属性的使用:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
你的浏览器不支持 audio 元素。
</audio>
亲自试一试 »
Style 实例
使用type属性指定 <style> 标签的媒体类型:
<style type="text/css">
h1 {color:red;}
p {color:blue;}
</style>
亲自试一试 »
浏览器支持
type
属性对每个元素都有以下浏览器支持:
元素 | |||||
---|---|---|---|---|---|
button | Yes | Yes | Yes | Yes | Yes |
embed | Yes | Yes | Yes | Yes | Yes |
input | Yes | Yes | Yes | Yes | Yes |
link | Yes | Yes | Yes | Yes | Yes |
object | Yes | Yes | Yes | Yes | Yes |
script | Yes | Yes | Yes | Yes | Yes |
source | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
style | Yes | Yes | Yes | Yes | Yes |