0

jquery 通貨入力があり、次のコードを使用しています。

$('input[name="precio"]').spinner({
    min:0,
    numberFormat: 'C'
});

グローバル化に応じて $ または € 記号を使用して数値を表示するため、入力は完全に機能します。

問題は、フォームを送信すると、この「5,00 €」のようなテキストが表示され、数値だけで 5.00 または 500 にしたいことです。

これを行う方法はありますか?前もって感謝します。

4

2 に答える 2

1

これは、現在の数値を取得する入力の「aria-valuenow」という属性です(フォーマットなし)

http://jsfiddle.net/ma8zd7mg/1/

 $("#spinner").spinner({
     min: 0,
     numberFormat: "C"
 });

$("#test").click(function(){
    alert($("#spinner").attr('aria-valuenow'));
});

編集(コメントで質問に答えるために)PHPで送信した後に値を取得するには、次のことができます。1.スピナーの数値を取得するプレースホルダー入力を作成し、その値が送信されます2.PHPを使用して追加のフォーマット文字 ($、.、および追加のゼロ)

次のような最初の方法をお勧めします。

$("#submit-btn").click(function(e){
    //prevent the form submission
    e.preventDefault();

    //add a placeholder input with the value of the spinner
    $("#my-from").append('<input/>', {
        'type': 'hidden',
        'name': 'spinner-value',
        'value': $("#spinner").attr('aria-valuenow')
    });

    //now submit the form
    $("#my-form").submit();
});

次に、PHPで「スピナー値」入力を取得できます

<?php
$spinner = $_REQUEST['spinner-value'];
....
....
?>
于 2014-09-09T19:34:25.623 に答える
0

わかりました、私は最終的にこれを私が望んでいた方法で行うことができました。JQueryUI からスピナーを拡張する currencyspinner という名前のプラグインを作成しました。コードは次のとおりです。

$.widget( "ui.currencyspinner", $.ui.spinner, {
     options: {
        numberFormat: 'C',  // Currency Format
        min:0,
        step:0.10
    },
    _create: function(){
        this.hidden = $('<input type="hidden" value="'+this.element.val()+'" name="'+this.element.attr('name')+'">');   // Create a hidden input with the same name and value
        this.element.removeAttr('name');    // remove the name of the original element
        this.element.before(this.hidden);   // insert the hidden element before the original element
        return this._super();
    },

    _refresh: function() {
        this.hidden.val(this._parse(this.element.val()));   // put the aria-valuenow on the original element
        return this._super();
    },

    _destroy: function(){
        this.element.attr('name',this.hidden.attr('name')); // put back the name on the original value
        this.hidden.remove();                               // remove the hidden element
        return this._super();
    }
});

同じ名前の非表示の入力を作成し、スピナーが更新されるたびに aria-valuenow の値を与えます。

currencyspinner を作成した後で currencyspinner にアクセスしようとしている場合は、使用できないことに注意$('input[name="nameoftheelement"]').currencyspinner(...);してください。これは、スピナー自体ではなく非表示の入力になるためです。

私はそれが誰かを助けることを願っています!

于 2014-10-02T11:54:09.010 に答える