嗨,我有一个表单,当我从组合框中选择一个与组合框值关联的值时,它会动态生成字段问题是我也有一个 jquery 计算函数,它将从 ajax 生成的文本框中计算百分比。任何人都可以帮助我这是我的 ajax 文件
<?php
session_start();
require("includes/dbconnect.php");
require("includes/function.php");
$zdb = $_SESSION["zdbyear"];
mysql_select_db($zdb);
$code = $_GET["code"];
$ztit = $_SESSION["tit"];
//browse($code);
$result = mysql_query("SELECT * FROM `loctype` WHERE code='".$code."'") or die(mysql_error());
require("includes/dbconnect.php");
$getcomp = mysql_query("SELECT * FROM `compyear` WHERE finyear='".$ztit."'") or die(mysql_error());
$st = mysql_fetch_array($getcomp);
$row = mysql_fetch_array($result);
echo "<table border='1'>";
echo "<tr>";
echo '<td align="left"> <font color="green"><b>Deposit</b></font> <input type="text" size="20" maxlength="40" name="deposit" value="'.$row["deposit"].'" class="qty form-input-rate" text-align:left ; /></td>';
echo '<td align="right"> <font color="red"><b>Rent</b></font> <input type="text" id="rent" size="20" maxlength="40" name="rent" value="'.$row["rent"].'" class="form-input-rate" /></td>';
echo '<td align="right"> <font color="#D2691E"><b>S.T</b></font> <input type="text" id="stperc" size="5" maxlength="40" name="servtax" style="width: 50px;" value="'.$st["stperc"].'" class="form-input-rate" text-align:left ; />%</td>';
echo '</tr>';
echo '<tr>';
echo '<td align="right"> <font color="green"><b>S.T</b></font> <input type="text" size="20" maxlength="40" id="stamt" name="stamt" value="" class="form-input-rate" text-align:left ; /></td>';
echo '<td align="right"> <font color="red"><b>Amount</b></font><input type="text" size="20" maxlength="40" id="totamt" name="totamt" value="" class="form-input-rate" readonly/></td>';
echo '<tr>';
echo "</table>";
}
?>
这是我的 jquery 计算部分
$(document).ready(function () {
$("#stperc").keyup(function () {
alert($("#stperc").val());
var value = $("#stperc").val();
var value2 = $("#rent").val();
$('#stamt').val((value * value2) / 100).toFixed(2);
});
$("#stperc").blur(function () {
var val = parseInt($("#rent").val());
$('#totamt').val(val + Number($("#stamt").val())).toFixed(2);
});
});