我正在尋找建立一個提交到數據庫(.asp)的網頁,但也計算出一個百分比。計算百分比.asp
百分比是8%。
理想我希望用戶鍵入的輸入框的量(例如讓說£100)
然後下方有可自動caluates的£100 + 8%(所以108£)的另一輸入框
我沒有得到一個線索如何開始,所以我沒有得到任何代碼
我正在尋找建立一個提交到數據庫(.asp)的網頁,但也計算出一個百分比。計算百分比.asp
百分比是8%。
理想我希望用戶鍵入的輸入框的量(例如讓說£100)
然後下方有可自動caluates的£100 + 8%(所以108£)的另一輸入框
我沒有得到一個線索如何開始,所以我沒有得到任何代碼
直播的jsfiddle:http://jsfiddle.net/5mB3Q/
這是您的jQuer y:
$("#val").on('keyup', function(){
$("#incPerc").text(parseInt($(this).val())*1.08);
});
您可能想要使用庫將輸入限制爲只能輸入數字。 是這樣的:Limit Textfield Input to digits only
添加第二個輸入http://jsfiddle.net/5mB3Q/1/ 和圓的兩個數字:
$("#val").on('keyup', function(){
var withPerc = parseFloat($(this).val())*1.08;
$("#incPerc").text(withPerc.toFixed(2));
$("#otherInput").val(withPerc.toFixed(2));
});
編輯:OK,因爲評論的全碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-2.0.0.js" type="text/javascript"></script>
</head>
<body>
<form>
<input id="val">
<input id="otherInput">
</form>
<script type="text/javascript">
$(document).ready(function() {
$("#val").on('keyup', function(){
var withPerc = parseFloat($(this).val())*0.08;
$("#incPerc").text(withPerc.toFixed(2));
$("#otherInput").val(withPerc.toFixed(2));
});
});
</script>
</body>
</html>
鏈接jQuery庫時,您忘記了協議。 (和doc.ready)
$('#output').text = (int)($('#input').text.Substring(0, $('#input').text.Length - 1)) * 1,08 + $('#input').text.Substring($('#input').text.Length - 1);
你可以開始使用javascript –