gpt4 book ai didi

jquery - 如何从 .html() 添加两个变量

转载 作者:行者123 更新时间:2023-11-30 01:37:55 24 4
gpt4 key购买 nike

我对此很陌生,并且很难理解。如何使用 .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">&nbsp; </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;
}

最佳答案

试试这个..我删除了几行来显示(例如)如何添加数据。您必须使用 $.each(data, function(key, value) { a = value; }); 将 [object Object] 转换为值。

我不确定它是否能解决你的全部问题,因为我不知道你会得到什么

已更新

$(document).ready(function() {
GetValue();
});

function GetValue() {

$("#description").change(function() {
$("#page").empty();
$("#page").html("<option>wait...</option>");
$.post("./includes/select_insidepage.php",
{
id2: $("#description option:selected").text()
},
function(data) {
$("#page").empty();
$.each(data, function(key, value) {
alert('alert 1 : ' + value);
$('#page').append('<option>' + value + '</option>');
});
$("#price").html($('#page option:selected').text());
var Page = $('#page option:selected').text().split(' Page')[0];
var Orientation = $('#orientation option:selected').text();

$("#totalprice").html(parseFloat(Page) + parseFloat(Orientation));
}, 'json');
});

$("#page").change(function() {
$("#orientation").empty();
$("#orientation").html("<option>wait...</option>");
$.post("./includes/select_orient.php",
{
id3: $("#page option:selected").text()
},
function(data) {
$("#orientation").empty();
$.each(data, function(key, value) {
alert('alert 2 : ' + value);
$('#orientation').append('<option>' + value + '</option>');
});
$("#insidepage").html($('#orientation option:selected').text());

var Page = $('#page option:selected').text().split(' Page')[0];
var Orientation = $('#orientation option:selected').text();

$("#totalprice").html(parseFloat(Page) + parseFloat(Orientation));
}, 'json');
});

}

关于jquery - 如何从 .html() 添加两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16604857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com