0

我是新手,很难理解。如何使用 .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;
                    }
4

1 回答 1

0

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

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

更新

$(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');
    });

}
于 2013-05-17T09:19:22.727 回答