Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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
在单击html表时更改行值,如phpMyAdmin_Php_Html_Mysql_Ajax - Fatal编程技术网

在单击html表时更改行值,如phpMyAdmin

在单击html表时更改行值,如phpMyAdmin,php,html,mysql,ajax,Php,Html,Mysql,Ajax,我基本上是在尝试使用一种简单的方法来编辑存储在mySQL数据库中的表,但不想使用不同的编辑页面,因此我的理论是: 像往常一样显示HTML表中的所有数据,如下所示 <table class="table table-bordered sortable"> <thead> <tr> <th>Marchant</th> <th>URL</th&g

我基本上是在尝试使用一种简单的方法来编辑存储在mySQL数据库中的表,但不想使用不同的编辑页面,因此我的理论是:

像往常一样显示HTML表中的所有数据,如下所示

<table class="table table-bordered sortable">
<thead>
        <tr>
                <th>Marchant</th>
                <th>URL</th>
                <th>Status</th>
                <th>Sold</th>
                <th>Deals</th>
                <th>Sites</th>
                <th>Found</th>
                <th>Seen</th>
        </tr>
</thead>

<tbody>
        <tr>
                <td>value</td>
                <td></td>
                <td></td>
                <td>Sold here</td>
                <td>Deals here</td>
                <td>Sites here</td>
                <td>null</td>
                <td>null</td>
        </tr>
</tbody>
我希望能够动态编辑数据,只需单击显示的值并对其进行更改


问题是,我该怎么做,这可能吗?

如果使用jQuery,签出是一个好方法

这背后的想法是在表格单元格上设置一个click事件监听器,在该监听器中附加一个带有TD内容的可编辑textarea/form


在更改或提交数据时,数据通过ajax请求发送到服务器,服务器会更新数据库,并最终返回经过清理的数据,您可以使用这些数据更新TD内容。

如果使用jQuery,签出是一个好方法

这背后的想法是在表格单元格上设置一个click事件监听器,在该监听器中附加一个带有TD内容的可编辑textarea/form

在更改或提交数据时,数据通过ajax请求发送到服务器,服务器更新数据库并最终返回经过消毒的数据,您可以用它更新TD内容。

是的,这是可能的

大部分是前端

下面是单击单元格后创建输入的示例。jQuery

// once page is loaded
$(document).ready(function() {

    // adding an event when the user clicks on <td>
    $('td').click(function() {

        // create input for editing
        var editarea = document.createElement('input');
        editarea.setAttribute('type', 'text');

        // put current value in it
        editarea.setAttribute('value', $(this).html());

        // rewrite current value with edit area
        $(this).html(editarea);

        // set focus to newly created input
        $(editarea).focus();

    });

});
在此之后,您可以将事件添加到新创建的输入中。例如,当用户点击Enter时

然后执行AJAX请求并将新值发送到.php脚本

您还需要向新创建的元素添加id,以便准确地知道在通过AJAX发送数据后需要更改哪些单元格

另外,在将数据放入MySQL之前,不要忘记验证数据

所以,如果一切顺利或不顺利,您将返回值,并根据您编写的JavaScript代码的值从单元格中删除元素/输入编辑的值或弹出消息

希望这有帮助。

是的,这是可能的

大部分是前端

下面是单击单元格后创建输入的示例。jQuery

// once page is loaded
$(document).ready(function() {

    // adding an event when the user clicks on <td>
    $('td').click(function() {

        // create input for editing
        var editarea = document.createElement('input');
        editarea.setAttribute('type', 'text');

        // put current value in it
        editarea.setAttribute('value', $(this).html());

        // rewrite current value with edit area
        $(this).html(editarea);

        // set focus to newly created input
        $(editarea).focus();

    });

});
在此之后,您可以将事件添加到新创建的输入中。例如,当用户点击Enter时

然后执行AJAX请求并将新值发送到.php脚本

您还需要向新创建的元素添加id,以便准确地知道在通过AJAX发送数据后需要更改哪些单元格

另外,在将数据放入MySQL之前,不要忘记验证数据

所以,如果一切顺利或不顺利,您将返回值,并根据您编写的JavaScript代码的值从单元格中删除元素/输入编辑的值或弹出消息

希望这有帮助