查找每个带有onchange js的文本框
foreach textboxes with onchange js on it
我试图在我拥有的每个文本框上都有一个onchange事件。但我的脚本只适用于第一行的文本框。有人能帮我吗?
<?php
foreach($get_order_details as $row_order_details):
?>
<form method = "post">
<tr>
<td width="180px"><?php echo $row_order_details['name']; ?></td>
<td width="180px"><?php echo $row_order_details['description']; ?></td>
<td width="180px"><?php echo $row_order_details['qty']; ?></td>
<td width="145px"><input type = "text" name = "received_qty" id = "received_qty" class = "form-control" onchange = "myFunction1();"/></td>
<td width = "145px"><input class = "form-control" type = "text" name = "cost" id = "cost" onchange = "myFunction();" /></td>
<th width = "145px"><input class = "form-control" type = "text" name = "total_cost" id = "total_cost" disabled /></th>
<td><button type = "submit" value = "" name = "received" class = "btn btn-primary">Receive</button></td>
</tr>
</form>
<?php
endforeach;
?>
这是我的javascript代码。
这是我的脚本
<script>
function myFunction1()
{
var received_qty = document.getElementById('received_qty').value;
var cost = document.getElementById('cost').value;
var total = received_qty * cost;
var cost = document.getElementById('total_cost').value = total;
}
function myFunction()
{
var received_qty = document.getElementById('received_qty').value;
var cost = document.getElementById('cost').value;
var total = received_qty * cost;
var cost = document.getElementById('total_cost').value = total;
}
</script>
事实上,你写了一些关于jquery将为您提供这个解决方案:)
JSFIDDLE
一些输入<input type="text" class="foo" id="i1" />
<input type="text" class="foo" id="i2" />
<input type="text" class="foo" id="i3" />
<input type="text" class="foo" id="i4" />
<input type="text" class="foo" id="i5" />
<input type="text" id="i6" />
<input type="text" id="i7" />
<input type="text" id="i8" />
<input type="text" id="i9" />
你jquery $(document).ready(function(){
$('.foo').on('change', function(){
alert($(this).val());
});
});
相关文章:
- Angular JS-文本框未在独立范围内更新
- 如何使用注入Firefox控制台的js文本来更改网站的背景图像-示例提供
- 如何从该文本的 onclick 方法中更改 d3.js 文本输入
- PHP/JS 文本差异
- Fabric.js文本转换不起作用
- 为什么可以't我得到了这个d3.js文本的边界框
- Beautifulsoup抓取数据,其中有js文本在中间
- angular js文本到语音转换api
- Chart.js文本颜色
- 正在将Fabric.js文本转换为路径
- 从列表中滚动的 Js 文本大小有限
- JS文本解析器不起作用
- JS- 文本区域行到 javascript 数组
- D3 中的 html.js文本标记
- 时刻.js文本格式和类
- require.js文本插件在文件名中添加“.js”
- JS 文本到 PHP 的数组
- js 文本文件的大小是否是其中的字符数加上一个
- 如何在预填充字段时清除iOS占位符JS文本
- D3.js文本输入(在svg中)将不透明度0转换为1 won't结束于1