国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目錄 搜索
Attributes accesskey (attribute) class (attribute) contenteditable (attribute) contextmenu (attribute) data-* (attribute) dir (attribute) draggable (attribute) dropzone (attribute) Global attributes hidden (attribute) id (attribute) itemid (attribute) itemprop (attribute) itemref (attribute) itemscope (attribute) itemtype (attribute) lang (attribute) slot (attribute) spellcheck (attribute) style (attribute) tabindex (attribute) title (attribute) translate (attribute) Elements a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 head header hr html i iframe img input input type="button" input type="checkbox" input type="color" input type="date" input type="datetime"-local input type="email" input type="file" input type="hidden" input type="image" input type="month" input type="number" input type="password" input type="radio" input type="range" input type="reset" input type="search" input type="submit" input type="tel" input type="text" input type="time" input type="url" input type="week" ins kbd label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt rtc ruby s samp script section select slot small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr Miscellaneous Attributes Block-level elements CORS enabled image CORS settings attributes Element Inline elements Kinds of HTML content Link types Microdata Optimizing your pages for speculative parsing Preloading content Reference Supported media formats Using the application cache Obsolete acronym applet basefont big blink center command content dir element font frame frameset hgroup image input type="datetime" isindex keygen listing marquee nextid noframes plaintext strike tt xmp
文字

元素<input type="button"> 是  <input>元素的特殊版本,被用來創(chuàng)建一個沒有默認值的可點擊按鈕。 它已經在HTML5被 <button>元素取代

<input type="button" value="Click Me">

注意:雖然<input>類型的元素"button"仍然是完全有效的HTML,但新<button>元素現(xiàn)在是創(chuàng)建按鈕的有利方式,具有一些優(yōu)勢。它支持使用"menu"按鈕作為彈出式菜單觸發(fā)器的類型,并且<button>在開始和結束標簽之間插入標簽文本,可以在標簽中包括HTML,甚至圖像。

用作按鈕標簽的DOMString

活動

點擊

支持的通用屬性

類型和價值

IDL屬性

方法

沒有

一個<input type="button">元素的value屬性包含DOMString一個用作按鈕的標簽。

<input type="button" value="Click Me">

如果你沒有指定一個value,你得到一個空的按鈕:

<input type="button">

Using buttons

<input type="button">元素沒有默認行為(與他們相似的:<input type="submit"><input type="reset">分別用于提交和重置表單)。要使按鈕做任何事情,你必須編寫JavaScript代碼來完成這項工作。

一個簡單的按鈕

我們首先創(chuàng)建一個帶有click事件處理程序的簡單按鈕來啟動我們的機器(當然,它會切換value按鈕和下面段落的文本內容):

<form> 
  <input type="button" value="Start machine"></form><p>The machine is stopped.</p>
var btn = document.querySelector('input');var txt = document.querySelector('p');btn.addEventListener('click', updateBtn);function updateBtn() {  if (btn.value === 'Start machine') {
    btn.value = 'Stop machine';
    txt.textContent = 'The machine has started!';  } else {
    btn.value = 'Start machine';
    txt.textContent = 'The machine is stopped.';  }}

該腳本獲取HTMLInputElement表示<input>DOM中的對象的引用,并將該引用保存在變量中btn。addEventListener()然后用于建立一個函數(shù),當click按鈕上發(fā)生事件時將運行該函數(shù)。

將鍵盤快捷鍵添加到按鈕

鍵盤快捷鍵(也稱為訪問鍵和鍵盤等價物)可讓用戶使用鍵盤上的鍵或鍵組合來觸發(fā)按鈕。要添加一個鍵盤快捷鍵到一個按鈕——你可以使用accesskey全局屬性。

在這個例子中,s被指定為訪問鍵(您需要按s加上您的瀏覽器/操作系統(tǒng)組合的特定修飾鍵;請參閱accesskey這些鍵的有用列表)。

<form>  <input type="button" value="Start machine" accesskey="s"></form><p>The machine is stopped.</p>

注意:以上例子的問題當然是用戶不知道訪問密鑰是什么!在真實網站中,您必須以不干擾網站設計的方式提供此信息(例如,通過提供易于訪問的鏈接指向有關網站訪問鍵的信息)。

禁用和啟用按鈕

要禁用按鈕,只需disabled在其上指定全局屬性,如下所示:

<input type="button" value="Disable me" disabled>

您可以在運行時通過設置disabledtrue或來啟用和禁用按鈕false。在這個例子中,我們的按鈕開始啟用,但是如果按下它,它將被禁用btn.disabled = true。setTimeout()然后用一個函數(shù)在兩秒鐘后將按鈕恢復到啟用狀態(tài)。

如果該disabled屬性沒有被指定,該按鈕disabled從其父元素繼承它的狀態(tài)。這樣就可以通過將元素組合在一個容器(如<fieldset>元素)中,然后disabled在容器上進行設置,從而一次啟用和禁用所有元素組。

下面的例子顯示了這一點。這與前面的例子非常相似,除了在按下第一個按鈕時disabled設置了屬性之外<fieldset>- 這會導致所有三個按鈕都被禁用,直到兩秒鐘超時。

:Firefox將不像其他的瀏覽器,默認情況下,堅持動態(tài)禁用狀態(tài)一的<button>整個頁面加載。使用該autocomplete屬性來控制此功能。

驗證

按鈕不參與約束驗證; 他們沒有真正的價值可以被約束。

示例

下面的例子展示了一個使用<canvas>元素和一些簡單的CSS和JavaScript 創(chuàng)建的非常簡單的繪圖應用程序(為了簡潔,我們將隱藏CSS)。頂部的兩個控件允許您選擇繪圖筆的顏色和大小。單擊按鈕時,會調用清除畫布的函數(shù)。

<div class="toolbar">  <input type="color" aria-label="select pen color">  <input type="range" min="2" max="50" value="30" aria-label="select pen size"><span class="output">30</span>  <input type="button" value="Clear canvas"></div><canvas class="myCanvas">  <p>Add suitable fallback here.</p></canvas>
var canvas = document.querySelector('.myCanvas');var width = canvas.width = window.innerWidth;var height = canvas.height = window.innerHeight-85;var ctx = canvas.getContext('2d');ctx.fillStyle = 'rgb(0,0,0)';ctx.fillRect(0,0,width,height);var colorPicker = document.querySelector('input[type="color"]');var sizePicker = document.querySelector('input[type="range"]');var output = document.querySelector('.output');var clearBtn = document.querySelector('input[type="button"]');// covert degrees to radiansfunction degToRad(degrees) {  return degrees * Math.PI / 180;};// update sizepicker output valuesizePicker.oninput = function() {
  output.textContent = sizePicker.value;}// store mouse pointer coordinates, and whether the button is pressedvar curX;var curY;var pressed = false;// update mouse pointer coordinatesdocument.onmousemove = function(e) {
  curX = (window.Event) ? e.pageX : e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  curY = (window.Event) ? e.pageY : e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);}canvas.onmousedown = function() {
  pressed = true;};canvas.onmouseup = function() {
  pressed = false;}clearBtn.onclick = function() {
  ctx.fillStyle = 'rgb(0,0,0)';
  ctx.fillRect(0,0,width,height);}function draw() {  if(pressed) {
    ctx.fillStyle = colorPicker.value;
    ctx.beginPath();
    ctx.arc(curX, curY-85, sizePicker.value, degToRad(0), degToRad(360), false);
    ctx.fill();  }  requestAnimationFrame(draw);}draw();

規(guī)范

Specification

Status

HTML Living StandardThe definition of '<input type="button">' in that specification.

Living Standard

HTML5The definition of '<input type="button">' in that specification.

Recommendation

瀏覽器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

1.0

1.0 (1.7 or earlier)

(Yes)

(Yes)

1.0

Feature

Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

(Yes)

4.0 (4.0)

(Yes)

(Yes)

(Yes)

上一篇: 下一篇: