dps43378 2013-06-15 08:57 采纳率: 0%
浏览 14

如何通过ajax对动态生成的文本框执行jquery计算

hi i have a form which dynamically generates fields when i select a value from a combo box with the value associated with the combo box value the problem is i have a jquery calculation function too which will calculate percentage from the textbox generated by ajax. can any one help me in this here is my ajax file

<?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>";
}
?>

here is my jquery calculation part

$(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);
    });
});    
  • 写回答

2条回答 默认 最新

  • dongxue9997 2013-06-15 09:01
    关注

    Use delegation:

    $("#some_table_id").on('keyup', '#stperc', function(){
      // do it here
    });
    

    Similarly you can delegate blur event

    $("#some_table_id").on('blur', '#stperc', function(){
      // do it here
    });
    

    Give an id to the table in your html code so that the action can be executed on any inputs added in that table (some_table_id is the dummy id I use)

    echo "<table border='1' id='some_table_id'>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了