2013-08-27 40 views
0

你好家伙我只想问我怎么能改变使用jquery中的事件的html属性值。例如,我有一个充满信息的用户列表,并有一个按钮更新和取消。用户信息是READONLY,但当用户单击按钮更新时,它将删除我的文本框中的READONLY属性。使用jQuery中的onclick事件更改HTML属性值

这里是我的简单的代码:

<div style="display: none" id="form_edit" class="k-content"> 
     <table border="0"> 

      <tr> 
       <td> 
        &nbsp;&nbsp;&nbsp;<label>P.O. #</label> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<input type="text" name="po" value="<?php echo $order_code; ?>" readonly="readonly" /> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<label>SUPPLIER NAME</label> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<input type="text" name="suppliername" value="<?php echo $sname; ?>" readonly="readonly"" /> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<label>Contact Person</label> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<input type="text" name="person" value="<?php echo $contactperson; ?>" readonly="readonly" /> 
       </td> 
      </tr> 

      <tr> 
       <td> 
        &nbsp;&nbsp;&nbsp;<label>TIN #</label> 
       </td> 
       <td> 
        &nbsp;&nbsp;&nbsp;<input type="text" name="tin" value="<?php echo $tin; ?>" readonly="readonly" /> 
       </td> 
      </tr> 

      <tr> 
       <td colspan="6" style="text-align: right"> 

        <input type="button" value="UPDATE" class="k-button" id="submit_form"/> 
        <input type="button" value="HIDE" class="k-button" id="close_form"/> 
       </td> 
      </tr> 


     </table> 
    </div> 

我的jQuery

$("a[name=edit_order]").click(function (e) { 
     $("#window_edit").data("kendoWindow").open(); 
     e.preventDefault(); 
    }); 

    $("a[name=remove_order]").click(function (e) { 
     $("#window_remove").data("kendoWindow").open(); 
     e.preventDefault(); 
    }); 

    /*here's the part that will remove the readonly attribute but how can i do that? 
    $("#update_supplier").click(function(){ 
     $("#form_edit").show({ 
      effect: "blind", 
      animation: 1000 
     }); 

     $("#update_supplier").hide({ 
      effect: "fade", 
      animation: 1000, 
     }); 
    }); 

    /*if close bring back again the readonly*/ 
    $("#close_form").click(function(){ 
     $("#form_edit").hide({ 
      effect: "blind", 
      animation: 1000 
     }); 

     $("#update_supplier").show({ 
      effect: "fade", 
      animation: 1000, 
     }); 
    }); 
+0

当你点击更新按钮的权利,你想从文本框中删除只读,但它也提交表单,当你点击更新按钮。 –

+0

对不起,我的错我会改变它按钮 – Jerielle

+0

检查我的编辑我确定它会帮助你解决你的问题 –

回答

4

试试这个代码:

$('#submit_form').on('click', function() { 
    $('input[name="suppliername"]').removeAttr('readonly'); 
}); 

检查我的编辑。

+0

解释downvote? –

+0

好吧,我会尝试也:) – Jerielle

+0

它的工作原理。但是如果我即将再次回到只读状态呢? – Jerielle

4

试试这个

$('#submit_form').on('click', function() { 
    $('input["readonly"]').removeAttr('readonly'); 
}); 
+0

你在哪里找到'.suppliername'类? –

+0

啊谢谢看到错误的想法,它是类 – Anton

+0

我不能看到这个名字的任何类? –

相关问题