English 中文(简体)
如何利用分类防止其他类型?
原标题:how to use jquery to prevent the others type?
  • 时间:2011-05-18 08:21:22
  •  标签:
  • jquery

html structure:

 1,  <input id="edit-field-14sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text" type="text"></div>


2,  <input id="edit-field-15sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text" type="text"></div>


3 , <input id="edit-field-16sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text" type="text"></div>


4 ,<input id="edit-field-17sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text" type="text"></div>


5 ,<input id="edit-field-18sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text" type="text"></div>

现在,如果1、2、3、投入箱具有价值,就可以在4、5中划出任何类型。

if the 4, 5, input box has value. then can t type anything in 1, 2, 3.

the following is my test code. but it can t work.

$(document).ready(function(){

$( #edit-field-14sq-und-0-value ).keyup(function() {
    if ($( #edit-field-16sq-und-0-value ).val().length > 0) {
        alert( you can t type them at the same time );
        $(this).val(  );
        $("#edit-field-15sq-und-0-value").val(  );
    }
})

});

the keyup function is give an error under firebug.

Edit: added "" to escape single quote in alert();

问题回答

change this line alert( you can t type them at the same time ); to

alert( you can t type them at the same time );

你可以这样做。 页: 1 http://jsfiddle.net/ynhat/x64dH/1/。

传真:

1,  <input id="edit-field-14sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text form-text-1" type="text"><br />


2,  <input id="edit-field-15sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text form-text-1" type="text"><br />


3, <input id="edit-field-16sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text form-text-1" type="text"><br />


4, <input id="edit-field-17sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text form-text-2" type="text"><br />


5, <input id="edit-field-18sq-und-0-value" name="field_14sq[und][0][value]" value="" size="12" maxlength="10" class="form-text form-text-2" type="text">

Javascript:

$(document).ready(function() {

    $( .form-text-1 ).keyup(function() {
        $( .form-text-2 ).removeAttr( disabled );
        $( .form-text-1 ).each(function(index){
            if ($(this).val() !=   ){
                $( .form-text-2 ).attr( disabled , disabled );
            }
        });
    })

    $( .form-text-2 ).keyup(function() {
        $( .form-text-1 ).removeAttr( disabled );
        $( .form-text-2 ).each(function(index){
            if ($(this).val() !=   ){
                $( .form-text-1 ).attr( disabled , disabled );
            }
        });
    })
});
$("#form1, #form2, #form3, #form4").change(function(){
  if ($(this).attr( value )!=  ){
    $("#form5, #form6, #form7, #form8,#form9, #form10, #form11").attr( readonly , readonly );
  } else {
    $("#form5, #form6, #form7, #form8,#form9, #form10, #form11").removeAttr( readonly );
  }
});

and so on with the other combinations

页: 1

jQuery("#form1").keyup(function () {
   if(jQuery("#form1").val() != "" && jQuery("#form2").val() != ""){
       jQuery("#form3").attr("disabled","disabled");
   }
});

页: 1





相关问题
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: &...

热门标签