文本输入返回“false”而不是Value

时间:2016-07-03 18:20:38

标签: javascript html css

var stattrak = self._convertString( $product.find( ".product-etchings" ).val() );
var nametag = self._convertString( $form.find( ".product-nametag" ).val() );

代码设置为在表单中查找这两个变量。有两个文本框,一个是蚀刻版,另一个是名称标签。当我在蚀刻盒中输入类似111的东西时,我得到一个“假”返回到stattrak var。同名的名牌。我不知道为什么这样做......

这是表单的HTML,抱歉。

<form class="add-to-cart" action="" method="post">
    <div>
        <label for="qty-1">Quantity &nbsp;&nbsp; </label>
        <input type="text" name="qty-1" id="qty-1" class="qty" value="1" /><br>
        <hr>
        <label for="stattrak">Etchings &nbsp;&nbsp;</label>
        <input type="text" name="stattrak" id="stattrak" class="product-etchings" value="none" /><br>
        <hr>
        <label for="nametag">Namtag &nbsp;&nbsp;</label>
        <input type="text" name="nametag" id="nametag" class="product-nametag" value="none" /><br><br>
    </div>
    <button type="submit" value="Add to cart" class="btn btn-success">Add To Cart</button>
</form>

然后是更多的Javascript:

handleAddToCartForm: function() {
        var self = this;
        self.$formAddToCart.each(function() {
            var $form = $( this );
            var $product = $form.parent();
            var price = self._convertString( $product.data( "price" ) );
            var name =  $product.data( "name" );

            $form.on( "submit", function() {
                var stattrak = self._convertString( $form.find( "#stattrak" ).val() );
                var nametag = self._convertString( $form.find( "#nametag" ).val() );
                var qty = self._convertString( $form.find( ".qty" ).val() );
                var subTotal = qty * price;
                var total = self._convertString( self.storage.getItem( self.total ) );
                var sTotal = total + subTotal;
                self.storage.setItem( self.total, sTotal );
                var stattrak = self._convertString( $form.find( ".stattrak" ).val() );
                var nametag = self._convertString( $form.find( ".nametag" ).val() );
                self._addToCart({
                    product: name,
                    price: price,
                    qty: qty,
                    stattrak: stattrak,
                    nametag: nametag
                });
                var shipping = self._convertString( self.storage.getItem( self.shippingRates ) );
                var shippingRates = self._calculateShipping( qty );
                var totalShipping = shipping + shippingRates;

                self.storage.setItem( self.shippingRates, totalShipping );
            });
        });
    },

0 个答案:

没有答案