jQuery检查选项val和selected,计算并发出警报

jQuery检查选项val和selected,计算并发出警报,jquery,option,selected,Jquery,Option,Selected,我需要做一些基于运输选项的计算。对于本例,我只想alert()新价格。我想在所选费用中增加6%并alert()。我无法真正修改下面的html,但如果选择了其中一个选项,它会添加selected: <select name="ShippingSpeedChoice" onchange="this.form.submit();"> <option value="0">PLEASE SELECT</option> <option value="701">

我需要做一些基于运输选项的计算。对于本例,我只想
alert()
新价格。我想在所选费用中增加6%并
alert()
。我无法真正修改下面的html,但如果选择了其中一个选项,它会添加
selected

<select name="ShippingSpeedChoice" onchange="this.form.submit();">
<option value="0">PLEASE SELECT</option>
<option value="701">UPS Ground $9.90 </option>
<option value="703">UPS 3Day Select® $30.88 </option>
</select>

您询问是否在DOM准备就绪时选择了该值。无论何时更改选项,都需要绑定事件处理程序来运行脚本

$(document).ready(function() {
    $("select").bind("change", function(){
      if ($("option[value='701']:selected", this)) {
        $("option[value='701']").each(function () {                                           
            var isthePrice = $(this).text().replace("UPS Ground $", "");
            var parsedShip = parseFloat(isthePrice);
            var doMath = parsedShip * 1.06;
            alert(doMath.toFixed(2) + " "); });
      }
    });                     
});

这是您的出发点,尽管您可能需要更具体地说明在一般情况下使用的选项。

这很有效,我将发布答案谢谢!啊,是的,这也行。我使用了$(document).ready(function(){
$(“select”).change(function(){$([value='701']:selected”).each(function(){var isthePrice=$(this).text().replace(“UPS Ground$”,“”);var parsedShip=parseFloat(isthePrice);var doMath=parsedShip*1.06;警报(doMath.toFixed(2)+“;});});})在我的实际页面上发生的情况是,警报弹出,然后页面将使用所选选项刷新。有没有办法使警报在重新加载后弹出?我不确定您是否希望表单提交,是吗?
$(document).ready(function() {
    $("select").bind("change", function(){
      if ($("option[value='701']:selected", this)) {
        $("option[value='701']").each(function () {                                           
            var isthePrice = $(this).text().replace("UPS Ground $", "");
            var parsedShip = parseFloat(isthePrice);
            var doMath = parsedShip * 1.06;
            alert(doMath.toFixed(2) + " "); });
      }
    });                     
});