如何使用jquery禁用第一个表单?

时间:2015-01-03 10:26:42

标签: jquery html

HTML:

<div id="container">
  <form id="form" name="form1">
     <input type="text" name="txtbox" value="Enter something" />
     <input name="salam" type="Submit" id="submitbtn" name="Submit" />
  </form>
</div>

 <div id="container1">
  <form id="form1" name="form1">
    <input type="text1" name="txtbox1" value="Enter something" />
    <input name="salam1" type="Submit" id="submitbtn1" name="Submit" />
  </form>
</div>

jQuery的:

 $(document).ready(function(){
   $('#form').submit(function(){
      $('input[id=submitbtn1]', this).attr('disabled', 'disabled');
   });
 });

7 个答案:

答案 0 :(得分:1)

$(document).ready(function(){
    $("#form").submit(function (event){
       event.preventDefault();         
    });
});

答案 1 :(得分:1)

在纯JavaScript中也很容易:

document.getElementById('submitbtn1').disabled = true;

OR

document.getElementById('submitbtn1').readOnly = true;

答案 2 :(得分:0)

查看first selector

$("form:first input").attr("disabled", true);

将从第一个input元素中选择所有form元素,并将其禁用。

答案 3 :(得分:0)

$(document).ready(function(){
  $('#form').submit(function(){
    $('#submitbtn1').attr('disabled', true);
  });
});

如果你只想在提交id = form

的表单时禁用id = submitbtn1的按钮

答案 4 :(得分:0)

这会在不等待提交

的情况下禁用它

&#13;
&#13;
$(document).ready(function(){
 
    $('#submitbtn1').attr('disabled', true);
 
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
 <form id="form" name="form1">
   <input type="text" name="txtbox" value="Enter something" />
   <input name="salam" type="Submit" id="submitbtn" name="Submit" />
 </form>
</div>
<div id="container1">
 <form id="form1" name="form1">
  <input type="text1" name="txtbox1" value="Enter something" />
  <input name="salam1" type="Submit" id="submitbtn1" name="Submit" />
 </form>
</div>
&#13;
&#13;
&#13;

答案 5 :(得分:0)

也是这个

$('input[id=submitbtn1]', this).attr('disabled', true);

答案 6 :(得分:0)

试试这个

$(document).ready(function(){

    $('#submitbtn1').attr('disabled', true);

});