Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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函数在blur或onclick上不起作用_Javascript_Jquery_Ajax_Html Table - Fatal编程技术网

Javascript函数在blur或onclick上不起作用

Javascript函数在blur或onclick上不起作用,javascript,jquery,ajax,html-table,Javascript,Jquery,Ajax,Html Table,我对ajax相当陌生,我不确定为什么我的函数没有启动。我用MySQL数据库中的值动态构建了一个表。我试图使表格能够内联编辑。 我要编辑的表格部分如下所示 <tr class="table-row"> <td><?php echo $row['idcpu']; ?></td> <?php echo "<td contenteditable=\"true\" onBlur=\"saveToDatabase(this

我对ajax相当陌生,我不确定为什么我的函数没有启动。我用MySQL数据库中的值动态构建了一个表。我试图使表格能够内联编辑。 我要编辑的表格部分如下所示

<tr class="table-row">
    <td><?php echo $row['idcpu']; ?></td>
    <?php 
    echo "<td contenteditable=\"true\" onBlur=\"saveToDatabase(this,'name','".$row['idcpu']."');\" onClick=\"showEdit(this);\">".$row['name']." </td>";
    echo "<td contenteditable=\"true\" onBlur=\"saveToDatabase(this,'description','".$row['idcpu']."');\" onClick=\"showEdit(this);\">".$row['description']."</td>";
    echo "<td contenteditable=\"true\" onBlur=\"saveToDatabase(this,'price','".$row['idcpu']."');\" onClick=\"showEdit(this);\">".$row['price']."</td>";
    echo "<td contenteditable=\"true\" onBlur=\"saveToDatabase(this,'quantity','".$row['idcpu']."');\" onClick=\"showEdit(this);\">".$row['quantity']."</td>"; ?>
</tr>

还有Javascript

<script>
    function saveToDatabase(editableObj,column,id) {
        $(editableObj).css("background","#FFF url(Loading_icon.gif) no-repeat right");
        $.ajax({
            url: "update/cpu.php",
            type: "POST",
            data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
            success: function(data){
                $(editableObj).css("background","#FDFDFD");
            }
       });
    }
</script>

函数saveToDatabase(editableObj,列,id){
$(editableObj.css(“背景”,即“#FFF url(Loading_icon.gif)无重复右键”);
$.ajax({
url:“update/cpu.php”,
类型:“POST”,
数据:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
成功:功能(数据){
$(editableObj).css(“背景”,“#fdfd”);
}
});
}

我尝试了很多不同的方法将代码输出到html,所以我知道这不是问题所在,但我可能很容易就错过了一些我需要的东西,因为我说我是一个相当新的人。任何帮助都将不胜感激

您的代码似乎运行良好。您可以在这里查看:

我已经用ChromeV49测试过了


正如@zer00ne所提到的,您应该尝试使用
,将其嵌套在
元素中,并在输入更改时运行ajax调用。浏览器支持要好得多。

使用
contenteditable
而不是
textarea
input
<代码>内容可编辑非常复杂,一点也不友好
textarea
input
是标准的、可靠的,并且有两种交叉浏览器方式来操作它们。我现在已经开始使用input,虽然我已经成功地使onclick工作,但我的onblur仍然不会启动函数saveToDatabase。背景没有改变,没有加载图像,PHP页面没有为表单元素运行,而不是为JS使用
obj.value
,或为jQuery使用
$(obj.val()
。使用
onchange
代替
onblur
。您需要熟悉表格的使用细节。这个资源是一个很好的开始:我已经更改了它,所以我现在使用文本输入而不是contenteditable。虽然您说它正在工作,但我编辑的字段是可编辑的,但更改不会保留。我引用的php文件没有运行,css更改也没有发生。我是否希望我的代码执行其他操作?我只需要它将值发送到PHP脚本我想我忘了提到我的PHP页面运行一个脚本,该脚本将使用输入的信息更新数据库