简体   繁体   English

使用jQuery删除只读属性

[英]remove readonly attribute using jquery

 <script type="text/javascript"> $('.show_edit').click(function() { $(this).hide(); $(this).siblings('.edit_faq').show(); $(this).parent().prev().find('.remove_att').removeAttr( "readonly" ); // this working perfect $(this).next().find('.remove_text').removeAttr( "readonly" ); // this is not working }); </script> 
 <?php foreach ($faq as $faq): ?> <div class="form-group"> <label class="col-sm-2 control-label">Question : </label> <div class="col-sm-8"> <input type="text" id="question" class="form-control remove_att" value="<?php echo $faq['faq_question'] ?>" placeholder="Enter the question" readonly="readonly" required=""> </div> <div class="col-sm-2" class="edit_all"> <button type="button" class="btn btn-warning btn-sm show_edit" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit"></i></button> <button type="button" id="<?php echo $faq['faq_id'] ?>" class="btn btn-success btn-sm edit_faq" data-toggle="tooltip" data-placement="bottom" title="Save" style="display: none"><i class="fa fa-floppy-o" ></i></button> <button type="button" class="btn btn-danger btn-sm delete_faq" id="<?php echo $faq['faq_id'] ?>" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-trash"></i>&nbsp;Delete</button> </div> </div> <div class="form-group"> <label class="col-sm-2 control-label">Answer : </label> <div class="col-sm-8"> <textarea class="form-control remove_text" id="answer" rows="5" placeholder="Type your answer..." required="required" readonly ><?php echo $faq['faq_answer'] ?></textarea> </div> </div> <?php endforeach; ?> 
   

i'm doing inline edit using save and edit button with the help of jquery. 我正在使用jquery的保存和编辑按钮进行内联编辑。 when i click on edit button input type="text" and textarea remove the readonly attribute. 当我单击编辑按钮输入type =“ text”和textarea时,将删除只读属性。 where input type="text" is working correctly,now i want to remove the readonly from textarea how to do this, any help would be appreciated 在输入type =“ text”正常工作的地方,现在我想从textarea删除readonly如何执行此操作,将不胜感激

Your .show_edit button wrapped in 2 divs: 您的.show_edit按钮分为2个div:

div.edit_all and div.form-group div.edit_alldiv.form-group

And, your textarea is located in the next div.form-group , So, try this: 而且,您的textarea位于下一个div.form-group中 ,因此,请尝试以下操作:

$('.show_edit').click(function() {
    $(this).hide();
    $(this).siblings('.edit_faq').show();
    $(this).parent().prev().find('.remove_att').removeAttr( "readonly" );
    $(this).closest('.form-group').next().find('.remove_text').removeAttr( "readonly" );
         // ^find the closest div.form-group parent 
});

You can find parent of .show_edit then again find its parent. 您可以找到.show_edit的父级,然后再次找到其父级。

Your textarea is present in next div where we find .remove_text class for remove readonly 您的textarea存在于下一个div中,我们在其中找到.remove_text类以删除只读

so try this : 所以试试这个:

<script type="text/javascript">
    jQuery(document).ready(function(){
     $('.show_edit').click(function() {
        $(this).hide();
        $(this).siblings('.edit_faq').show();
        $(this).parent().prev().find('.remove_att').removeAttr( "readonly" ); 
        $(this).parent().parent().next().find('.remove_text').removeAttr( "readonly" ); 
     })
    });   
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM