这里有多个文本框可供使用...我需要在jquery中使用keyup函数时乘以日率和不允许的日期。我试图将这两个值相乘,输出将显示在另一个相等的文本框中。输出值不会显示在该相等的文本框中。
PHP代码
<?php
$qry = mysql_query("SELECT * FROM vefm_ts_engr_details WHERE job_number='" . $jobno . "'", $dbcon);
$norows = mysql_num_rows($qry);
$i = 1;
while ($srow = mysql_fetch_array($qry)) {
$isql = mysql_query("SELECT * FROM vefm_engineer_details WHERE ecode='" . $srow['ecode_id'] . "'", $dbcon);
$ires = mysql_fetch_array($isql);
?>
<div class="row">
<div class="form-group col-sm-2" align="right">
<label>Day Rate of </label>
<label class="fonts" style="color:purple"><?php echo $ires['engr_name']; ?></label>
</div>
<div class="form-group col-sm-3" align="left">
<input type="text" id="dayrate<?php echo $i ;?>" name="dayrate[]" class="form-control" value="">
<input type="hidden" id="allowed_days<?php echo $i ;?>" name="allowed_days[]" class="form-control" value="<?php echo $srow['allowed_days'];?>">
<span id="errmsg1" style="color:red;"></span>
</div>
<div class="form-group col-sm-2" align="left">
<label class="fonts"><?php echo $srow['allowed_days']; ?></label>
<label> (NO of days allowed)</label>
</div>
<div class="form-group col-sm-3" align="left">
<input type="text" id="amt<?php echo $i ;?>" name="amt" class="form-control" value="" >
</div>
</div>
<?php
$i++;
}
?>
JQuery代码:
var rowCount = $('#totalrows').val();
var i;
alert(rowCount);
for (i = 1; i <= rowCount; i++) {
var allowday = $('#allowed_days' + i).val();
// alert(allowday);
$('#dayrate' + i).keypress(function(e) {
// alert(allowday);
var x = 1;
if (x<=i) {
$('#amt'+x).val((String.fromCharCode(e.which))*allowday);
x++;
}
});
}
答案 0 :(得分:0)
用你的jquery代码包装:
jQuery(document).ready(function($){
var rowCount = $('input[name="dayrate[]"]').length;
var i;
//alert(rowCount);
for (i = 1; i <= rowCount; i++) {
var allowday = $('#allowed_days' + i).val();
// alert(allowday);
$('#dayrate' + i).keypress(function(e) {
// alert(allowday);
var x = 1;
if (x<=i) {
$('#amt'+x).val((String.fromCharCode(e.which))*allowday);
x++;
}
});
}
});
还使用以下代码来计算名称为dayrate []
的输入总数$('input[name="dayrate[]"]').length;
这可能适合你。