English 中文(简体)
案文投入的价值大于此。 j 质量
原标题:text input value greater than.. jQuery

我正在使用字句,并在案文投入价值大于40时试图传递信息。

<input type="text" name="quantity" size="2" value="<?php echo wpsc_cart_item_quantity(); ?>" />

Now i want to throw a message (alert) when this text field contains value greater than 40 and also want to reset its value to My wordpress theme uses jquery 1.71 I am doing the following:

jQuery("input[type= text ][name= quantity ]").change(function() {
if (this.val >= 41) {
    alert("To order quantity greater than 40 please use the contact form.");
    this.val ==   ;
    this.focus();
    return false;
}
});

感谢。

最佳回答

您首先需要将<条码>这一条/代码>与<条码><><$/code>的功能加以总结,因为这是通过甄选程序而不是单项标而退还的多功能元素,而<条码><>功能不能在这类物体上获得。

Also, you need to call the val() function with parenthesis, otherwise you re working on the body of the function, not the value it returns.

最后,在派任说明上有一个打字。 您至少应当有<条码>t.val = ,但自<条码> val<条码>以来赢得t工作是一种功能,而不是一种变数。 工作法典应当这样考虑:

$("input[type= text ][name= quantity ]").change(function() {
    if ($(this).val() >= 41) {
        alert("To order quantity greater than 40 please use the contact form.");
        $(this).val(  );
        $(this).focus();
    }        
});    
问题回答

Well, you were nearly there, use:

jQuery("input[type= text ][name= quantity ]").change(function() {
    if (parseInt($(this).val(),10) > 40) {
        alert("To order quantity greater than 40 please use the contact form.");
        this.value ==   ;
        /* or with jQuery: $(this).val(  ); */
        $(this).focus();
        return false;
    }
});

参考资料:





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签