2014-09-30 3 views
-1

뭔가 다른 형태 내의 모든 속성을 변경 :jQuery를 내가 폼 요소와 형태가

@using (Html.BeginForm("Edit", "UserProfile", FormMethod.Post, new { id = "EditUserForm", @class = "form-horizontal form-bordered" })) 
{ 

    <div class="form-group"> 
     @Html.LabelFor(m => m.Email, new { @class = "col-sm-4 control-label" }) 
     <div class="col-sm-8"> 
      @Html.TextBoxFor(m => m.Email, new { @class = "form-control", type = "text", @readonly = "readonly" }) 
     </div> 
    </div><!-- form-group --> 

    <div class="form-group"> 
     @Html.LabelFor(m => m.Name, new { @class = "col-sm-4 control-label" }) 
     <div class="col-sm-6"> 
      @Html.TextBoxFor(m => m.Name, new { @class = "form-control", type = "text", @readonly = "readonly" }) 
     </div> 
    </div><!-- form-group --> 

} 

을 나는 모든 요소 형태 내에서 변경하기를 통해 루프 jQuery를 사용하려면/제거 readonly 특성 버튼/요소를 클릭하면

어떻게하면 되나요? 내가 아는 이드의 단 한 항목의 속성을 변경하는 방법 만 알면됩니까?

html은 면도기 용입니다.

+0

질문이 클라이언트 측만 인 경우 렌더링 된 HTML을 제공하는 것이 훨씬 더 좋습니다. – Regent

+0

내 코드는이 질문에도 사용할 수 있습니다. @ zapnologica –

답변

2

당신은 사용할 수 있습니다

$(function() { 
    $('#EditUserForm [readonly]').prop('readonly', false); 
}); 
1

양식에 입력란 만 있기 때문에 이 같은

시도 뭔가 :

$('input[readonly]').removeAttr('readonly'); 

또는

$('#EditUserForm input[readonly]').removeAttr('readonly'); 

Working Demo

+0

예, 지금은 나에게 좋을 것 같습니다. OP의 HTML을 이해하는 것은 매우 어렵지만, 이것이 필요한 것이라고 생각합니다. +1. – Regent

+1

@ Regent ..yes OP가 'Asp.Net MVC' 서버 측 기술 ..all ..' @ Html.TextBoxfor()'를 사용하여 간단한 텍스트 상자를 생성합니다 ... –

1

FIDDLE

$(".form-group input[type=text").each(function(){ 
     var attr=$(this).attr('readonly'); 
     if(typeof attr !==typeof undefined || attr!==false) 
      $(this).removeAttr('readonly'); 
    }); 
+1

'typeof attr! == typeof undefined' can 'attr! == undefined'로 단순화하십시오. – Regent

+0

예,하지만이 방법이 가장 정확합니다. –

+0

아니요, 불필요한 기호 일뿐입니다. '! =='는 피연산자 타입을 비교하는 반면,'! ='는 값만을 찾아서 하나의 타입으로 변환합니다. – Regent