Javascript的parseInt函数似乎没有完全奏效.
parseInt("01") returns 1
parseInt("02") returns 2
parseInt("03") returns 3
parseInt("04") returns 4
parseInt("05") returns 5
parseInt("06") returns 6
parseInt("07") returns 7
parseInt("08") returns 0
parseInt("09") returns 0
Run Code Online (Sandbox Code Playgroud)
你无法解释.试试看.(的jsfiddle)
我正在做的事情:
我有一个javascript程序,当单击一个按钮时,从一个表单中的4个文本框中获取4个字符串,并将这些字符串输出到格式化的文本区域.
function testResults(form){
var errorhandle1 = parseInt(document.myForm.Item_Code.value);
var errorhandle2 = parseInt(document.myForm.Item_Cost.value);
var errorhandle3 = parseInt(document.myForm.Quantity.value);
//above variables are for error handling.
var d = " ";
var subtotal = parseInt(form.Item_Cost.value) * parseInt(form.Quantity.value);
var subtotalValue = parseInt(document.myForm.Subtotal.value);
var testVar = "Item Code: " + form.Item_Code.value + d +
"Item Name: " + form.Item_Name.value + d +
"Item Cost: " + form.Item_Cost.value + d +
"Quantity: " + form.Quantity.value + '\n';
document.myForm.myTextarea.value += testVar;
document.myForm.Subtotal.value = parseInt(subtotal) + subtotalValue;
document.myForm.Sales_Tax.value = …Run Code Online (Sandbox Code Playgroud) 我有这些HTML代码,它们可以从数据库中获取数据。我将数组设置为HTML输入。
HTML代码
<table>
<thead>
<tr>
<th>Category</th>
<th>January</th>
<th>February</th>
</tr>
</thead>
<tbody>
<?php
$sql = DB::getInstance()->FetchArray("select * from table");
if(count($sql) > 0)
{
foreach($sql as $row)
{
$i = 0;
if($i == 0)
{?>
<tr>
<td><input type="text" class="cat1" id="cat1" name="cat1[]" value="<?php echo $row['CATEGORY']; ?>" placeholder="" readonly></td>
<td><input type="text" class="jan1" id="jan1" name="jan1[]" value="<?php echo (($row['MONTH']=='JANUARY')? $row['TOTAL']:''); ?>" placeholder="" readonly></td>
<td><input type="text" class="feb1" id="feb1" name="feb1[]" value="<?php echo (($row['MONTH']=='FEBRUARY')? $row['TOTAL']:''); ?>" placeholder="" readonly></td>
</tr>
<?php
}
else
{?>
<tr>
<td></td>
<td><input type="text" class="jan1" id="jan1" …Run Code Online (Sandbox Code Playgroud) 我必须使用 javascript 使用表单字段中的值进行小计算。计算公式如下:
totalIncome = income1 + income2 *0.7 + income3/48 + (income4 * 0.7)/48;
的值income1,income2,income3和income4可以是零和字段可以是空的。
我的代码如下:
<tr id="row">
<td>No. of Dependant(s)</td>
<td><input type="text" id="income1" value=""></td>
<td><input type="text" id="income2" value=""></td>
<td><input type="text" id="income3" value=""></td>
<td><input type="text" id="income4" value=""></td>
<td><input type="text" id="totalIncome" readonly></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我用于我的公式的公式脚本如下:
var income1 = document.getElementById("income1");
var income2 = document.getElementById("income2");
var income3 = document.getElementById("income3");
var income4 = document.getElementById("income4");
var totalIncome = document.getElementById("totalIncome");
var inputs = Array.prototype.slice.call(document.querySelectorAll("td > input"));
inputs.forEach(function(input){
input.addEventListener("blur", …Run Code Online (Sandbox Code Playgroud)