Я новичок в Javascript, и кто-то помог мне с этим сценарием, он отлично работает на Chrome, но он не работает в Firefox, и еще не тестировал его в IE, но я хочу, чтобы он работал вво всех браузерах, и я не так много знаю о jQuery, как о его переводе
function displayTotal()
{
var tableRows = document.getElementById('budgetTable').getElementsByTagName('tr');
var totalDays = tableRows.length - 3; //Don't count the header rows and the Total rows
var totalPrice = 0;
var price = filterNum(document.getElementById( 'txtPrice' ).value);
var totalField = document.getElementById('txtTotal');
var tempHours = 0;
var tempTotal = 0;
for(var i = 0; i < totalDays; i++)
{
tempHours = document.getElementById("end" + i).value - document.getElementById("start" + i).value;
tempTotal = tempHours * price;
document.getElementById("total" + i).innerHTML = formatCurrency(tempTotal);
totalPrice += tempTotal;
console.log(i, "Start:" + document.getElementById("start" + i).value, "End:" + document.getElementById("end" + i).value, "Hours:" + tempHours, "Total:" + tempTotal);
}
totalField.value = formatCurrency(totalPrice);
}
function addRowToTable()
{
var tbl = document.getElementById('budgetTable');
var lastRow = tbl.rows.length - 2;
var iteration = lastRow;
var entry = iteration - 1; //because we started with day0, etc
var row = tbl.insertRow(lastRow);
// day cell
var cellDay = row.insertCell(0);
cellDay.appendChild(createInput('text','day' + entry, '', displayTotal));
// start cell
var cellStart = row.insertCell(1);
cellStart.appendChild(createInput('text','start' + entry, 0, displayTotal));
// end cell
var cellEnd = row.insertCell(2);
cellEnd.appendChild(createInput('text','end' + entry, 0, displayTotal));
// total cell
var cellTotal = row.insertCell(3);
cellTotal.id = 'total' + entry;
}
function createInput(type, id, value, action)
{
var el = document.createElement('input');
el.type = type;
el.id = id;
el.value = value;
el.onkeyup = action;
return el;
}
function filterNum(str)
{
re = /^\$|,/g;
// remove "$" and ","
return str.replace(re, "");
}
function formatCurrency(num)
{
num = isNaN(num) || num === '' || num === null ? 0.00 : num;
return parseFloat(num).toFixed(2);
}
Любая помощь будет приветствоваться, так как я действительно не знаю, где мне не хватает, тогда укажите здесь.*
РЕДАКТИРОВАТЬ: хорошо, это странно, но в Firefox, когда я включаю firebug, чтобы попытаться отладить его, ... это работает.