Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
Jquery 如何在td中插入文本字段值_Jquery_Html - Fatal编程技术网

Jquery 如何在td中插入文本字段值

Jquery 如何在td中插入文本字段值,jquery,html,Jquery,Html,我需要使用jQuery在表中插入textfield中的值。 我有一个包含三个单元格的表,我使用jQuery函数在表中附加元素,但我无法在td中获取textfield的值 这是我的桌子: <table id="tableCmp" border name="tableCmp" style="width:25%;border-collapse:collapse;"> <tr> <th width="5%"></th> <th>Intitul

我需要使用jQuery在表中插入textfield中的值。 我有一个包含三个单元格的表,我使用jQuery函数在表中附加元素,但我无法在td中获取textfield的值

这是我的桌子:

<table id="tableCmp" border name="tableCmp" style="width:25%;border-collapse:collapse;">

<tr>
<th width="5%"></th>
<th>Intitule Compagnie</th>     
<th width="15%">Action</th>
</tr>
</table>
<input type="text" id="text" />
function showdata()
 {
 $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>$('#text').val()</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }

国际公司
行动
这是我的文本字段:

<table id="tableCmp" border name="tableCmp" style="width:25%;border-collapse:collapse;">

<tr>
<th width="5%"></th>
<th>Intitule Compagnie</th>     
<th width="15%">Action</th>
</tr>
</table>
<input type="text" id="text" />
function showdata()
 {
 $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>$('#text').val()</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }

这是我的功能:

<table id="tableCmp" border name="tableCmp" style="width:25%;border-collapse:collapse;">

<tr>
<th width="5%"></th>
<th>Intitule Compagnie</th>     
<th width="15%">Action</th>
</tr>
</table>
<input type="text" id="text" />
function showdata()
 {
 $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>$('#text').val()</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }
函数showdata()
{
$('#tableCmp').append('$('#text').val()');
}
您可以尝试以下方法:

function showdata()
 {
   $('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>' + $("#text").val() +'</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
 }
函数showdata()
{
$('#tableCmp').append('+$(“#text”).val()+'';
}
如果您在括号内添加了$(“#text”).val(),请尝试使用此选项

$('#tableCmp').append('<tr><td  style="text-align:center;"><input type="checkbox" name="myTextEditBox" id="myTextEditBox"></td><td>' + $('#text').val() + '</td><td><input type="button" value="M" /><input type="button" value="X" /></td></tr>');
$('#tableCmp').append('+$('#text').val()+'');

代码中的错误引用。这只是问题中的打字错误吗?我想
$(“#text”).val()
应该从引号中展开:)@A.Wolff更正了它。:)