JS(JQuery)-未定义

拉里·爱迪生(Larry Edison)

其实我不是js开发人员。获取元素时有一些问题(select.value)我的浏览器对我说:未捕获的ReferenceError:未定义getprice

据我了解,jQuery可以通过id元素的select.value获取。我该如何解决?谢谢!

js代码:

function getprice() {
    $.ajax({
        type: "POST",
        url: "<?=Core_Config::$Link?>store/cart",
        data: {
            pay_type: $("#pay_type").val();,
            delivery_type: $("#delivery_type").val();,
            totalprice: "<?=$total?>"
        },

        success: function(html) {
            $("#content22").html(html);
        }
    });
}

HTML:

<tr>
    <td><span class="required">*</span> Delivery:</td>
    <td>
        <select name="address[delivery]" id="delivery_type">
        <? foreach ($this->db->query($this->delivery) as $delivery ): ?>
          <option value="<?=$delivery['id']?>"><?=$delivery['name']?> (<?=$delivery['cost']?> грн)</option>
        <? endforeach; ?>
      </select>
    </td>
</tr>
<tr>
    <td><span class="required">*</span> Payment:</td>
    <td>
        <select name="address[paytype]" id="pay_type" onchange="getprice();">
        <? foreach ($this->db->query($this->payType) as $paytype ): ?>
            <option value="<?=$paytype['id']?>"><?=$paytype['name']?> (<?=$paytype['cost']?> грн)</option>
        <? endforeach; ?>
     </select>
    </td>
</tr>
在线托马斯

function getprice() {
    $.ajax({
        type: "POST",
        url: "<?=Core_Config::$Link?>store/cart",
        data: {
            pay_type: $("#pay_type").val(), //<--removed ;
            delivery_type: $("#delivery_type").val(), //<--removed ; also
            totalprice: "<?=$total?>"
        },

        success: function(html) {
            $("#content22").html(html);
        }
    });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
   <td><span class="required">*</span> Delivery:</td>
   <td><select name="address[delivery]" id="delivery_type">
       <? foreach ($this->db->query($this->delivery) as $delivery ): ?>
            <option value="<?=$delivery['id']?>"><?=$delivery['name']?> (<?=$delivery['cost']?> грн)</option>
        <? endforeach; ?>
        </select> </td>
</tr>
<tr>
    <td><span class="required">*</span> Payment:</td>
    <td><select name="address[paytype]" id="pay_type" onchange="getprice();">
           <? foreach ($this->db->query($this->payType) as $paytype ): ?>
                   <option value="<?=$paytype['id']?>"><?=$paytype['name']?> (<?=$paytype['cost']?> грн)</option>
                            <? endforeach; ?>
               </select> </td>
                </tr>

如果您包含jQuery,它就可以工作!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章