Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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 使用Jquery获取表中可编辑td的值_Javascript_Jquery_Html_Html Table - Fatal编程技术网

Javascript 使用Jquery获取表中可编辑td的值

Javascript 使用Jquery获取表中可编辑td的值,javascript,jquery,html,html-table,Javascript,Jquery,Html,Html Table,我有一个动态表: <table> <tbody> <tr> <td>1</td> <td contenteditable='true'>Value1</td> </tr> <tr> <td>2</td> <td

我有一个动态表:

<table>
    <tbody>
        <tr>
            <td>1</td>
            <td contenteditable='true'>Value1</td>
        </tr>
        <tr>
            <td>2</td>
            <td contenteditable='true'>Value2</td>
        </tr>
    </tbody>
</table>

因此,我的问题是如何在
blur
事件中获取新值,以及如何准确获取修改的
td

如果要显示输入的每个字符,请使用
而不是
focus

您可以使用
$(this.text()
$(this.html()
获取td中的值

希望这有帮助


一小条
$('table td')。在('input',function(){
console.log($(this.text());
});
$('table td')。在('blur',函数(){
log(“模糊新值:+$(this.text());
});

1.
价值1
2.
价值2

如果要显示输入的每个字符,请使用
输入
而不是
焦点

您可以使用
$(this.text()
$(this.html()
获取td中的值

希望这有帮助


一小条
$('table td')。在('input',function(){
console.log($(this.text());
});
$('table td')。在('blur',函数(){
log(“模糊新值:+$(this.text());
});

1.
价值1
2.
价值2
所以我的问题是如何在模糊事件中获得新值

使用该方法。(或者,如果您不想要标记)这不是值,而是新内容。(
td
元素没有值。)

以及如何准确地得到修改的td

blur
事件回调中是
this

因此:


旁注:由于
td
元素在表外无效,
$('table td')
$('td')
完全相同

所以我的问题是如何在模糊事件中获得新值

使用该方法。(或者,如果您不想要标记)这不是值,而是新内容。(
td
元素没有值。)

以及如何准确地得到修改的td

blur
事件回调中是
this

因此:


旁注:由于
td
元素在表外无效,
$('table td')
$('td')

使用
text()
函数如下所示

$('table td').blur(function () {
    console.log($(this).text());
});
使用
text()
函数,如下所示

$('table td').blur(function () {
    console.log($(this).text());
});
当一个元素(或其中的任何元素)失去焦点时,就会发生focusout事件。 focusout()方法附加一个函数,当元素或其中的任何元素上发生focusout事件时,该函数将运行

当一个元素(或其中的任何元素)失去焦点时,就会发生focusout事件。 focusout()方法附加一个函数,以便在元素或其内部的任何元素上发生focusout事件时运行。

您可以使用jQuery或函数访问
td
(它没有值!),例如:
$(this).text()
$(this).html()

$(函数(){
$('table td').focus(函数(){
控制台日志(“焦点”);
console.log(“echo each input”);//显示每个carac输入
});
$('table td').blur(函数(){
控制台日志(“模糊”);
console.log(“回显新值:+$(this.text());//显示新值
});
});

1.
价值1
2.
价值2
您可以使用jQuery或函数访问
td
(它没有价值!)的内容,例如:
$(this).text()或
$(this.html()

$(函数(){
$('table td').focus(函数(){
控制台日志(“焦点”);
console.log(“echo each input”);//显示每个carac输入
});
$('table td').blur(函数(){
控制台日志(“模糊”);
console.log(“回显新值:+$(this.text());//显示新值
});
});

1.
价值1
2.
价值2
使用
$(this).text()

使用
$(this.text()


您应该使用keyup而不是focus来获取每个字母,如果您想要获取正确的字母大小写,则应该使用keypress而不是keyup

选中此项

$(函数(){
$('table td')。按键(功能(e){
var singleChar=String.fromCharCode(e.keyCode)
控制台日志(“焦点”);
console.log(singleChar);//显示每个输入的carac
});
$('table td').blur(函数(){
控制台日志(“模糊”);
console.log($(this.text());//显示新值
});
});

1.
价值1
2.
价值2

如果要获得正确的字母大小写,您应该使用键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键向上键

选中此项

$(函数(){
$('table td')。按键(功能(e){
var singleChar=String.fromCharCode(e.keyCode)
控制台日志(“焦点”);
console.log(singleChar);//显示每个输入的carac
});
$('table td').blur(函数(){
控制台日志(“模糊”);
console.log($(this.text());//显示新值
});
});

1.
价值1
2.
价值2

但这不会显示任何类型的字符。但这不会显示任何类型的字符。
$('table td').blur(function () {
    console.log($(this).text());
});
$('table td').focusout(function(){
    alert($(this).text());
});
$('table td').blur(function(){
    alert($(this).text());
});