A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/ja/docs/Web/HTML/Reference/Global_attributes/autocorrect below:

HTML autocorrect グãƒãƒ¼ãƒãƒ«å±žæ€§ - HTML

この例では、 autocorrect 属性を使用して自動修正を無効または有効にする方法を示しています。

HTML

HTML マークアップは、<button>、「名前」の <input> 要素(type="text")、「経歴」の <textarea> 要素、および 2 つの <label> 要素を定義しています。

"username" の要素には autocorrect="off" が設定されています。名前の自動修正は煩わしいからです。 bio には autocorrect の値が指定されていません。つまり、有効になっているということです(off 以外の任意の要素を設定することもできます)。

<button id="reset">リセット</button>
<label for="username">名前: </label>
<input id="username" name="username" type="text" autocorrect="off" />
<label for="bio">経歴: </label>
<textarea id="bio" name="bio"></textarea>
#log {
  height: 75px;
  overflow: scroll;
  padding: 0.5rem;
  border: 1px solid black;
}

button,
input,
textarea {
  display: block;
}
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}
JavaScript

このコードは、プロトタイプに autocorrect が存在するかどうかをチェックすることで、それが対応しているかどうかを確認します。 存在しない場合は、その事実が記録されます。 存在する場合は、各テキスト入力要素の autocorrect プロパティの値が記録されます。

ボタンにクリックハンドラーを追加し、入力テキストとログ出力をリセットできるようにします。

const resetButton = document.querySelector("#reset");
const userNameElement = document.querySelector("#username");
const bioElement = document.querySelector("#bio");

if (!("autocorrect" in HTMLElement.prototype)) {
  log("自動修正に対応していません");
} else {
  log(`userNameElement.autocorrect: ${userNameElement.autocorrect}`);
  log(`bioElement.autocorrect: ${bioElement.autocorrect}`);
}

resetButton.addEventListener("click", (e) => {
  userNameElement.value = "";
  bioElement.value = "";
});
結果

自動修正機能がブラウザーに対応している場合、「経歴」と「名前」の入力欄の下記にあるログ出力領域に、「経歴」の入力欄には有効であるが、「名前」の入力欄には有効ではないことを示すメッセージが表示されます。

名前と経歴のテキスト入力項目に不正なテキストを入力します。 端末に指定された単語の代替が存在する場合、この単語が「経歴」入力項目(のみ)のテキストの自動修正に使用されます。


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4