По умолчанию значение value не срабатывает
В калькуляторе при значении value прописывает, но не считает, необходимо вставать в поле и производить редактирование чтобы начался расчет
<!DOCTYPE HTML> <head> <meta http-equiv="content-type" content="text/html" /> <title>Калькулятор</title> <link rel="stylesheet" href="css/stylecal.css" type="text/css" media="screen" /> <script type='text/javascript' src='js/jquery.js'></script> </head> <body> <script src="js/calc.js" type="text/javascript"></script> <input id="sum" onkeypress="return testKey(e)" autocomplete="off" type="text" value="3000" /><br /> <table id="main_table" cellspacing="0" width="100%"> <tbody> <tr class="italic"> <td></td><td></td><td>1</td><td>2</td><td>3</td><td>4</td> </tr> <tr class="black"> <td nowrap="nowrap">текст:</td> <td nowrap="nowrap" class="dates"></td> <td nowrap="nowrap" class="cases">5%</td> <td nowrap="nowrap" class="cases">10%</td> <td nowrap="nowrap" class="cases">15%</td> <td nowrap="nowrap" class="cases">20%</td> </tr> <tr> <td></td> <td nowrap="nowrap" class="dates"></td> <td nowrap="nowrap" class="case1">0.00</td> <td nowrap="nowrap" class="case2 greyColor">0.00</td> <td nowrap="nowrap" class="case3 greyColor">0.00</td> <td nowrap="nowrap" class="case4 greyColor">0.00</td> </tr> <tr> <td></td> <td nowrap="nowrap" class="dates"></td> <td nowrap="nowrap" class="case1">0.00</td> <td nowrap="nowrap" class="case2 greyColor">0.00</td> <td nowrap="nowrap" class="case3 greyColor">0.00</td> <td nowrap="nowrap" class="case4 greyColor">0.00</td> </tr> </tbody> </table> </body> </html> Вот кодик
function addZero(vNumber) {
return ((vNumber < 10) ? "0" : "") + vNumber;
}
function dateToMyDate(input) {
var mlang = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря']
var date = new Date(input);
var day = addZero(date.getDate());
var mоnth = date.getMonth();
var year = date.getFullYear();
var today = day + ' ' + mlang[mоnth] + ' ' + year + ' г.';
return today;
}
$(document).ready(function(){
var percents = [ 1.05 , 1.1 , 1.15 , 1.2 ];
var current = new Date, i = 0, plus = 0;
$('.dates').each(function() {
plus = (i > 0) ? 1 : 0;
current.setMonth(current.getMonth() + plus);
$(this).html(dateToMyDate(current.getTime()));
i++;
});
$('#sum').keypress(function(event){
var key, keyChar;
if(!event) var event = window.event;
if (event.keyCode) key = event.keyCode;
else if(event.which) key = event.which;
if(key==null || key==0 || key==8 || key==13 || key==9 || key==46 || key==37 || key==39 ) return true;
keyChar=String.fromCharCode(key);
if(!/\d/.test(keyChar)) return false;
});
$('#sum').keyup(function(event){
var sum = $('#sum').val();
var prev = 0, step = 0, val = 0,last_val= 0;
for (i = 1; i < percents.length + 1; i++) {
prev = 0;
step = 0;
$('.case' + i).each(function() {
if (step == 0) prev = sum;
val = (prev * percents[i - 1]).toFixed(2);
$(this).html( val.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ') )
prev = val;
step++;
});
}
});
});
Подскажите пожалуйста что нужно добавить чтобы значения атрибута value передавалось для автоматического подсчета? |
Pultik, у вас функции работает по событию onkeyup...
вызовите это событие после загрузки страницы
//document.getElementById("sum").onkeyup();
$('#sum').keyup();
|
lord2kim, спасибо, что откликнулись, вертел я его не получается у меня, дополнил первый пост, выложил верстку и js. Если не сложно, подскажите, что нужно сделать.
|
Pultik, уберите событие onkeypress из input id="sum" (10 строка HTML-кода)
перед последними закрывающимися скобками в JS-файле (60 строка) напишите
$('#sum').keyup();
|
| Часовой пояс GMT +3, время: 22:06. |