JavaScriptを使用してHTML要素にoninput属性を追加しますか?
このために、addEventListener()と一緒にdocument.getElementById()の概念を使用します。以下はJavaScriptコードです-
例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<label> Enter the value:</label>
<input id="enterValue" type="text">
</body>
<script>
document.getElementById('enterValue').addEventListener("input", function () {
console.log('you have entered the value');
});
</script>
</html> 上記のプログラムを実行するには、ファイル名を保存します anyName.html(index.html) ファイルを右クリックして、VSコードエディターでライブサーバーで開くオプションを選択します。
出力
ユーザーが値を入力すると-
-
JavaScriptを使用してHTMLテーブルのすべての要素にIF条件を適用しますか?
これには、document.querySelectorAll.forEach()を使用できます。 例 以下はコードです- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> &
-
HTMLoninputイベント属性
HTML oninputイベント属性は、ユーザーがHTMLドキュメントのinput /textareaHTML要素に入力を入力したときにトリガーされます。 構文 以下は構文です- <tagname oninput=”script”></tagname> 例 入力イベント属性のHTMLの例を見てみましょう- <!DOCTYPE html> <html> <head> <style> body { color: #000; &nbs