絶対値を返す
サンプルソース
<input type="text" id="txt1" value="-100"> <input type="text" id="txt2"> <input type="button" value="絶対値を表示" onclick="document.all.txt2.value = Math.abs(document.all.txt1.value)"> |
解説
Math.abs()で絶対値を返します。実行結果
関連する内容
<input type="text" id="txt1" value="-100"> <input type="text" id="txt2"> <input type="button" value="絶対値を表示" onclick="document.all.txt2.value = Math.abs(document.all.txt1.value)"> |