-1

I have a problem with euro symbol. Suppose a value like 20€ Now i want to extract the value to get 20. But jQuery can't recognize € symbol. Please anyone help me out.

4

4 回答 4

1
$('#your-element').val().replace(/\u20ac/g, '');
于 2013-08-22T23:56:28.870 回答
1

您可以简单地使用输入值的 parseInt 来执行此操作。尝试这个:

var price = document.getElementById('input').value;
var number = parseInt(price, 10);
alert(number);
于 2013-08-23T00:08:06.367 回答
1

我认为这是因为 HTML 中的欧元符号有转义字符和欧元;所以你最终会得到 20 & euro; 而不是 20 欧元。我只是复制了角色本身并将其放置在我想要和工作的地方。所以而不是

<script>
        $(document).ready(
                function(){
                        $("#creditlbl").text("20 &euro;").html();
                }
        );
</script>

我写

 <script>
        $(document).ready(
                function(){
                        $("#creditlbl").text("20 €").html();
                }
        );
</script>
于 2015-05-05T09:32:21.173 回答
0

您的问题不在于 jQuery(它并不真正关心您使用什么字符,而是在其他地方)。这是证明(演示):

<input id='input' value='20€'/><button id='getVal'>Extract</button>

<script>
  $('#getVal').on('click', function() {
    alert($('#input').val().split('€')[0]);
  })
</script>
于 2013-08-22T23:55:50.287 回答