简体   繁体   中英

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

I have a table that is passed via ajax and displayed. 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.

When I click a in the table that has been passed, I would like to take the data convert it to a input field. Each TD has a class of table2, so in theory this should be simple.

$(".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.

If I try creating php variables, and passing the form data that way, I get an illegal XML error.

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:

$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!");

I received the same error message when I pasted that line to my IDE, Eclipse PHP Development Tools . 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错误并立即检测到

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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