Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在按钮上从上述所有元素中删除只读道具单击_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何在按钮上从上述所有元素中删除只读道具单击

Javascript 如何在按钮上从上述所有元素中删除只读道具单击,javascript,jquery,html,Javascript,Jquery,Html,我有一个带有输入字段的表单,其中readonly为true 我还有一个编辑按钮,我想让它在点击编辑按钮时,该行的所有输入字段都将为readonly false, 但是我不知道如何在这个TR中定位所有的TD>输入 谢谢 密码 <tr> <td> <img src="http://placehold.it/150x150" alt=""> </td> <td> <input name="textinput" plac

我有一个带有输入字段的表单,其中readonly为true

我还有一个编辑按钮,我想让它在点击编辑按钮时,该行的所有输入字段都将为readonly false, 但是我不知道如何在这个TR中定位所有的TD>输入

谢谢

密码

<tr>
<td>
    <img src="http://placehold.it/150x150" alt="">
</td>
<td>
    <input name="textinput" placeholder="" value="Olympus E-M1 mark II Body" class="" type="text" style="width: 100%;" readonly>
</td>
<td>
    <input name="textinput" placeholder="" value="Olympus" class="" type="text" style="width: 100%;" readonly>
</td>
<td>
    <input name="textinput" placeholder="" value="1" class="" type="text" style="width: 100%;" readonly>
</td>
<td>
    <input name="textinput" placeholder="" value="&euro; 1999,00" class="" type="text" style="width: 100%;" readonly>
</td>
<td class="total-price">
    <input name="textinput" placeholder="" value="&euro; 1999,00" class="" type="text" style="width: 100%;" readonly>
</td>
<td>
    <a href="#">
        // The edit button
        <i class="fa fa-edit" style="color: #C7225C; font-size: 20px;"></i>
    </a>
    <a href="#">
        <i class="fa fa-trash" style="color: #C7225C; font-size: 20px;"></i>
    </a>
</td>

使用
$('input[name=textinput]')。removeProp('readonly')
或者试试
$('input[name=textinput]')。removeAttr('readonly')

请查看此

将您的HTML修改为

<a href="#" class="edit">
    // The edit button
    <i class="fa fa-edit" style="color: #C7225C; font-size: 20px;"></i>
</a>
$('.fa edit').parent()。单击(函数(e){
e、 预防默认值()
$(this).closest('tr').find('input').removeAttr('readonly'))
})


您可以尝试使用道具而不是属性。

What?所有的
input
都有相同的
名称
?我还没有更改,这只是前端。对有问题的输入使用方法
$('.fa.fa edit')。on('click',function(){$(this).parents('tr').first().find('input').prop('readonly',false);})
这是完美的@kosmos,谢谢你将此作为答案发布,我会批准。如何在上面的TR中只针对只读,我有多行这样。
$('input[name=textinput]')
这将感谢你的帮助!
$('.edit').on('click', function(e){
    e.preventDefault()
    $(this).closest('tr').find(':input').removeProp('readonly');
})
$('.button').on('click', function(){
    var $this = $(this),
       tr = $this.closest('tr');

    tr.find('input[type="text"]').attr("readonly", false); 
});