我无法获得动态创建的输入值。
我想用用户输入的数字创建动态输入,然后计算此输入的总和
HTML代码:
<input disabled type="text" id="totalPrice" value="{$tv}">
(Entrer le nbr ) <input type="text" id="member" name="member" value="" class="price" onkeypress="addFields(event)"> <input type="checkbox" name="Checkbox" id="checkbox1" value="1" /><br />
&#13;
这是用于创建输入的JavaScript代码
<script>
function addFields(){
var number = document.getElementById("member").value;
var container = document.getElementById("container");
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
for (i=0;i<number;i++){
container.appendChild(document.createTextNode("Svp entrer L : " + (i+1)));
var input = document.createElement("input");
var input1 = document.createElement("Checkbox");
input.type = "text";
input.className = "price1";
container.appendChild(input);
container.appendChild(document.createElement("br"));
}
}
</script>
&#13;
以下是我遇到问题的JQuery代码:
<script>
$(document).ready(function(){
$('price').keyup(function () {
// initialize the sum (total price) to zero
var sum = 0;
// we use jQuery each() to loop through all the textbox with 'price' class
// and compute the sum for each loop
$('.price').each(function() {
sum += Number($(this).val());
});
// set the computed value to 'totalPrice' textbox
$('#totalPrice').val(sum);
});
});
</script>
&#13;