关于jquery取值问题?以下value1取到的值一直为0,请问各位是什么情况?
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>hello world</title>
<script type="text/javascript" src="../jquery/jquery-1.1.3.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input:first").keyup(function () {
var value = $(this).val();
var value1 = $("#unit_price").val();
$("#total_price").text(value);
$("#totalcount").text(value);
});
});
</script>
</head>
<body>
<table cellspacing="5" cellpadding="5">
<tr>
<td> </td>
<td colspan="7"><strong>提交订单</strong></td>
</tr>
<tr>
<td> </td>
<td colspan="7"><hr color="#87CEFA" size="1" width="600"></td>
</tr>
<tr align="left">
<td> </td>
<th>名称</th>
<th> </th>
<th>数量</th>
<th> </th>
<th>单价</th>
<th> </th>
<th>总价</th>
</tr>
<tr>
<td> </td>
<td width="50%" name="summary" id="summary">巧克力</td>
<td> </td>
<td class="num"><input type="text" value="1" name="num" id="num"/></td>
<td>*</td>
<td name="unit_price" id="unit_price">10</td>
<td>=</td>
<td name="total_price" id="total_price"></td>
</tr>
<tr>
<td> </td>
<td colspan="7"><hr color="#87CEFA" size="1" width="600"></td>
</tr>
<tr style="color:#FF0000;font: bold;">
<td> </td>
<td>应付总额:</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>=</td>
<td id="totalcount"></td>
</tr>
</table>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>hello world</title>
<script type="text/javascript" src="../jquery/jquery-1.1.3.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input:first").keyup(function () {
var value = $(this).val();
var value1 = $("#unit_price").val();
$("#total_price").text(value);
$("#totalcount").text(value);
});
});
</script>
</head>
<body>
<table cellspacing="5" cellpadding="5">
<tr>
<td> </td>
<td colspan="7"><strong>提交订单</strong></td>
</tr>
<tr>
<td> </td>
<td colspan="7"><hr color="#87CEFA" size="1" width="600"></td>
</tr>
<tr align="left">
<td> </td>
<th>名称</th>
<th> </th>
<th>数量</th>
<th> </th>
<th>单价</th>
<th> </th>
<th>总价</th>
</tr>
<tr>
<td> </td>
<td width="50%" name="summary" id="summary">巧克力</td>
<td> </td>
<td class="num"><input type="text" value="1" name="num" id="num"/></td>
<td>*</td>
<td name="unit_price" id="unit_price">10</td>
<td>=</td>
<td name="total_price" id="total_price"></td>
</tr>
<tr>
<td> </td>
<td colspan="7"><hr color="#87CEFA" size="1" width="600"></td>
</tr>
<tr style="color:#FF0000;font: bold;">
<td> </td>
<td>应付总额:</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>=</td>
<td id="totalcount"></td>
</tr>
</table>
</body>
</html> 展开
2个回答
展开全部
$(function(){
$("#num").keyup(function () {
var value1 = Number($("#unit_price").text()); //通过文本获取 在这里无法通过value获取td的内容
var value = $(this).val();
if(isNaN(Number(value))){
value=1; //输入数字以外的可以设置为1或者0
}
$("#total_price").text(value*value1); //设置总价格
$("#totalcount").text(value);
});
});
});
$("#num").keyup(function () {
var value1 = Number($("#unit_price").text()); //通过文本获取 在这里无法通过value获取td的内容
var value = $(this).val();
if(isNaN(Number(value))){
value=1; //输入数字以外的可以设置为1或者0
}
$("#total_price").text(value*value1); //设置总价格
$("#totalcount").text(value);
});
});
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询