我是新手,很难理解。如何使用 .html() 添加两个变量。我得到的只是 Nan(不是数字)或 [object Object]。我已经尝试过 parseInt 和 +。
$("select#description").change(function()
{
$("select#page").html("<option>wait...</option>");
var id2 = $("select#description option:selected").attr('value');
$.post("./includes/select_insidepage.php", {id2:id2},
function(data){
$("select#page").removeAttr("disabled");
$("select#page").html(data);
//show price---------------------------
$("#price").html(data);
//start----------------------orientation
$("select#page").change(function()
{
$("select#orientation").html("<option>wait...</option>");
var id3 = $("select#page option:selected").attr('value');
$.post("./includes/select_orient.php", {id3:id3},
function(data1){
$("select#orientation").removeAttr("disabled");
$("select#orientation").html(data1);
//show insidepagePrice----------
$("label#insidepage").html(data1);
//computation------------------
var pagePrice = $("#insidepage2").html(data1);
var prodPrice = $("#price2").html(data);
$("#totalprice").html(+pagePrice + +prodPrice);
将从 jquery 显示的 html
<tbody>
<tr class="top row">
<td align="left"> <select id="description"></select>
</td>
<td align="center"> <label id="price"> </label></td>
</tr>
<tr class="side">
<td align="left"><select id="page"></select>
</td>
<td align="center"> <label id="insidepage"> </label></td>
</tr>
<tfoot>
<tr>
<td colspan="3"> </td>
<td class="leftfoot" align="left"> <b> subtotal </b></td>
<td class="rightfoot" align="center"><label id="totalprice"> </label> </td>
将显示在下拉列表中的查询
public function ShowType()
{
$sql = "SELECT * FROM description WHERE id_cat = $_POST[id]";
$res = mysql_query($sql,$this->conn);
$type = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$type .= '<option value="' . $row['id_type'] . '">' . $row['descrip'] . '</option>';
}
return $type;
}
public function productPrice()
{
$sql = "SELECT prodPrice FROM description WHERE id_type = $_POST[id2]";
$res = mysql_query($sql,$this->conn);
$row = mysql_fetch_array($res);
$price = '<label>' . $row['prodPrice'] . '</label>';
return $price;
}
public function ShowPage()
{
$sql = "SELECT * FROM insidepage WHERE id_p = $_POST[id2]";
$res = mysql_query($sql,$this->conn);
$page = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$page .= '<option value="' . $row['id_price'] . '">' . $row['insidepage'] . '</option>';
}
return $page;
}
public function insidepagePrice()
{
$sql = "SELECT pagePrice FROM insidepage WHERE id_price = $_POST[id3]";
$res = mysql_query($sql,$this->conn);
$row = mysql_fetch_array($res);
$inside = '<label>' . $row['pagePrice'] . '</label>';
return $inside;
}