简体   繁体   English

如何将表格中的html数据转换为输入形式?

[英]How to I convert html data in table to a input form?

I have a table that is passed via ajax and displayed. 我有一个通过ajax传递并显示的表。 When the code is passed, it also passed all the javascript associated with the pass, as the code doesn't seem to work if I just put it in the page that it is being passed to. 传递代码时,它还会传递与传递相关的所有javascript,因为如果我只是将其放在传递给它的页面中,则该代码似乎无法正常工作。

When I click a in the table that has been passed, I would like to take the data convert it to a input field. 当我单击已通过的表中的a时,我想将数据转换为输入字段。 Each TD has a class of table2, so in theory this should be simple. 每个TD都有一类table2,因此从理论上讲这应该很简单。

$(".table2").click(
    function () {
        var html = $(this).html();
        $(this).empty().html('<input name="" type="text" value="' + html + ' " />);
    });

But I get a 但是我得到了

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /products.php on line 90

When I try to do an ajax call on it. 当我尝试对其进行ajax调用时。

If I try creating php variables, and passing the form data that way, I get an illegal XML error. 如果我尝试创建php变量,并以这种方式传递表单数据,则会收到非法的XML错误。

Any ideas? 有任何想法吗?

EDIT 编辑

The reason I didn't include the PHP is that it is rather lengthy, and all it is doing is echoing some HTML/JS: 我没有包括PHP的原因是它相当冗长,并且它所做的只是回显一些HTML / JS:

$dbh=mysql_connect ("name","user", "pass") or die('I cannot connect to the database because:'. mysql_error());

        echo '<script type="text/javascript" charset="utf-8">
        $(".table2").click(
        function () {
            var html = $(this).html();
            $(this).empty().html('<input name="" type="text" value="' + html + ' " />');
        }); 


    });


    </script>

    <table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="table2">data</td>
    <td class="table2">data</td>
  </tr>
   <tr>
    <td class="table2">data</td>
    <td class="table2">data</td>
  </tr>
</table>
        ';

And it works fine is I replace 它可以正常工作,如果我更换

$(this).empty().html('<input name="" type="text" value="' + html + ' " />');

With something like alert("you click me!"); 带有类似alert(“ you click me!”);

I received the same error message when I pasted that line to my IDE, Eclipse PHP Development Tools . 将该行粘贴到IDE( Eclipse PHP开发工具)中时,我收到了相同的错误消息。 I removed a few unnecessary quotes and it took away the red underlines and here is the function. 我删除了一些不必要的引号,并删除了红色下划线,这里是函数。

$(this).empty().html("<input name="" type="text" value="' + html + ' " />");
    $(this).empty().html('<input name="" type="text" value="' + html + ' " />);

you dont have ' 你没有

try this 尝试这个

    $(this).empty().html('<input name="" type="text" value="' + html + ' " />');

使用php IDE避免这种sintax错误并立即检测到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM