JavaScriptにユーザーからのHTML入力を取得させ、解析して表示させますか?
HTML入力値は文字列です。文字列を整数に変換するには、parseInt()を使用します。
例
以下はコードです-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<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>
<body>
<input type="text" id="txtInput" placeholder="Enter a number">
<button type="button" onclick="result();">GetANumber</button>
</body>
<script>
function result() {
var numberValue = document.getElementById("txtInput").value;
if (!isNaN(numberValue))
console.log("The value=" + parseInt(numberValue));
else
console.log("Please enter the integer value..");
}
</script>
</html> 上記のプログラムを実行するには、ファイル名「anyName.html(index.html)」を保存します。ファイルを右クリックし、VSCodeEditorで[OpenwithLiveServer]オプションを選択します。
出力
これにより、コンソールに次の出力が生成されます-
次に、テキストボックスに値を入力します。
ボタンを押すと、次の出力が得られます。
これにより、次の出力が生成されます-
コンソールの出力-
-
trタグからidを取得し、JavaScriptを使用して新しいtdに表示するにはどうすればよいですか?
以下が私たちのテーブルだとしましょう- <table> <tr id='StudentDetails'> <th>StudentName</th> <th>StudentCountryName</th> </tr> <tr id='FirstRow'> <td&
-
テキストウィジェットに入力してtkinterにテキストを表示するにはどうすればよいですか?
Tkinterのテキストを使用できます テキストを挿入し、情報を表示し、テキストから出力を取得するウィジェット ウィジェット。 テキストでユーザー入力を取得するには ウィジェット、 get()を使用する必要があります 方法。例を見て、どのように機能するかを見てみましょう。 例 # Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry(&quo