2014-11-05 17 views
-1

我有一個下拉菜單,我有一些價值,我想在文本框中準確地獲得下拉值。如何使用文本框中的下拉值作爲十進制值

我能夠做到這一點,但這裏的十進制值可用它不來正確

我得到的值這樣的0.25 = 025和0.50 = 050

我應該怎麼做才能達到我的輸出

像0.25 = 0.25和0.50 = 0.50

Qty <select name="product_qty"> 
        <option value="0.25">250gm</option> 
        <option value="0.50">500gm</option> 
        <option value="1">1kg</option> 
        <option value="2">2kg</option> 
+1

讓我們來看看代碼。 – mainstreetmark 2014-11-05 15:12:11

+1

請顯示您的jQuery。 – nicael 2014-11-05 15:14:38

+0

@nicael我沒有使用j查詢我只使用這個代碼 – 2014-11-05 15:15:58

回答

0

薩蒂揚沒有你的代碼是很難告訴你在做什麼錯。這是一個jsfiddle,希望它有幫助。

http://jsfiddle.net/sheth/efxgpsq0/

$(function() { 
    $("select") 
     .change(function() { 
     var strText = ""; 
     $("select option:selected").each(function() { 
      strText += $(this).text() + " "; 
     }); 
     var strValue = ""; 
     $("select option:selected").each(function() { 
      strValue += $(this).val() + " "; 
     }); 

     $("#textoutput").text(strText); 
     $("#qty_selected").val(strText); 

     $("#valueoutput").text(strValue); 
     $("#qty_value_selected").val(strValue); 

    }) 
    .change(); 
}); 
相關問題