dparivln22034 2014-09-28 11:23
浏览 25
已采纳

更改行jquery中元素的属性

I want to remove the disabled attribute of the text fields in a table when a user clicked the edit button from the selected row, but i don't know how I will filter the text fields that i want to change.

here is my php:

        $query_select = "SELECT `users_id`,`users_studno`,`users_fname`,`users_lname`,`users_email`,`users_password` FROM `tbl_usersinfo` LIMIT 20";
        if($run_query = mysqli_query($con,$query_select))
        {

            while($row = mysqli_fetch_assoc($run_query))
            {
                $id_val = htmlentities($row['users_id']);
                $studno_val = htmlentities($row['users_studno']);
                $fname_val = htmlentities($row['users_fname']);
                $lname_val = htmlentities($row['users_lname']);
                $email_val = htmlentities($row['users_email']);
                $password_val = htmlentities($row['users_password']);

                echo "<tr class = 'special_rows'>";
                    echo "<td>"."<input type = 'checkbox' value = 'id_val' style = 'cursor:pointer; '>"."</td>";
                    echo "<td>".$id_val."</td>";
                    echo "<td>"."<input type = 'text' value = '$studno_val' class = 'data_field' disabled>"."</td>";
                    echo "<td>"."<input type = 'text' value = '$fname_val' class = 'data_field' disabled>"."</td>";
                    echo "<td>"."<input type = 'text' value = '$lname_val' class = 'data_field' disabled>"."</td>";
                    echo "<td>"."<input type = 'text' value = '$email_val' class = 'data_field' disabled>"."</td>";
                    echo "<td>"."<input type = 'text' value = '$password_val' class = 'data_field' disabled>"."</td>";
                    echo "<td>"."<a style = 'cursor:pointer' class = 'edit'>edit</a> <a style = 'cursor:pointer' class = 'save'>delete</a>"."</td>";
                echo "</tr>";
            }
        }

here is my jquery:

var edit = 0;
var save = false;

$('.edit').click(function()
{
    if( edit %2 == 0)
    {
        $('#tbl_users').find('tr').click( function(){
          alert('You clicked row '+ ($(this).index()) );
        $(this).index().$('.data_field').removeAttr('disabled');
        });
        $(this).text('save');

    }
    else
    {
        $(this).text('edit');
    }
    edit++;
});

example: i clicked the edit button from the first row, all the first row textfields should remove all their disabled properties.

  • 写回答

2条回答 默认 最新

  • duadpnld426905 2014-09-28 11:42
    关注

    You can try this:

    $('.data_field', this).prop('disabled', false);
    

    instead of:

    $(this).index().$('.data_field').removeAttr('disabled');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器