2012-05-24 92 views
0

我想循环通过我的页面上的特定窗体。我基本上想要在页面加载后禁用或设置每个字段的只读。jquery通过一个表单循环

我想我可以构建每个循环,但我不知道如何使它在页面上的表格中注明,以便它好好尝试一下我的头触摸输入等

这里我的表单的一个小版本:

<form id="account_information" class="stdform stdform2" method="post" action=""> 
    <p> 
     <label>First Name</label> 
     <span class="field"> 
      <input type="text" name="fname" id="firstname" class="smallinput" /> 
     </span> 
    </p> 
    <p> 
     <label>Last Name</label> 
     <span class="field"> 
      <input type="text" name="lname" id="lastname" class="smallinput" /> 
     </span> 
    </p> 
</form> 

在此先感谢您的帮助!

回答

3
$(function() { 

    $('form#account_information :input').prop('disabled', true).prop('readonly', true); 

}) 
+0

如果你使用一个id,没有指定'form'的要点。 – Andrew

+0

使用'[type = text]'不是最好的解决方案。 – VisioN

+0

谢谢大家对于非常快速和正确的答案,每个选项似乎都可以做到这一点 –

2

将所有输入禁用:

$(function() { 
    $('#account_information :input').prop('disabled', true); 
}) 

工作的例子 - http://jsfiddle.net/9VAKB/

3

这里有一个选项:

$(function() { 
    $("#account_information :input") 
     .prop("disabled", true)  // To disable 
     .prop("readonly", true); // To set readonly 
}); 

DEMO:http://jsfiddle.net/xdpC8/