|
2つの数字の大きい数字・小さい数字を表示する
サンプルソース
<html>
<body>
<input type="text" id="txt1" value="15">
<input type="text" id="txt2" value="45">
<input type="button" value="大きい数字を表示する" onclick="alert(Math.max(document.all.txt1.value,document.all.txt2.value))">
<input type="button" value="小さい数字を表示する" onclick="alert(Math.min(document.all.txt1.value,document.all.txt2.value))">
</body>
</html>
|
解説
Math.max(a,b)でa,bの大きい方を返す。
Math.min(a,b)でa,bの小さい方を返す。
サンプル
関連する内容
|
スポンサードリンク
|