duanqiao1926 2014-10-15 21:50
浏览 272

如何获取<td> </ td>标签的帖子值

I need to post these values of my td tags as this an editable table using jquery. I'm not sure if the issue here is with the script or the td tags? Currently my var_dump($_POST) is returning no values.

See below code, the td tags are about 10 lines down:

<h2><u>Edit</u></h2>
<form action="ajax/name.php" name="edit_template_form" id="edit_template_form" method="post">
    <?php print "<table border=\"1\" class=\"editableTable\">
    <tr>
    <th>Template Name</th>
    <th>Template Description</th>
    </tr>";
        foreach($res as $row){ 
            $temp_description = $row['template_description'];
        echo "<tr>";
        echo "<td id=\"edit_name\" name=\"edit_name\">". $row['template_name']. "</td>";
        echo "<td id=\"edit_template\" name=\"edit_template\">". nl2br($temp_description). "</td>";
        echo "<tr/>"; 
        } 
    print "</table>"; ?>
</form>
<div id="template_edit"></div>

name.php

var_dump($_POST);

if (isset($_POST['edit_template'])) {
$template_edit = $db->escape($_POST['edit_template']);

$user = $db->escape($user);
$db->update('templates', array('template_description' => $template_edit), 'AND userID="'.$user.'"');

echo $_POST['edit_template'];
}


if (isset($_POST['edit_name'])) {   
$template_name = $db->escape($_POST['edit_name']);

$user = $db->escape($user);
$db->update('templates', array('template_name' => $template_name), 'AND userID="'.$user.'"');

echo $_POST['edit_name'];
}

script.js

$(function () {
$("td").dblclick(function () {

    var OriginalContent = $(this).text();

    $(this).addClass("cellEditing");
    $(this).html("<input type='text' value='" + OriginalContent + "' />");
    $(this).children().first().focus();

        $(this).children().first().keypress(function (e) {
            if (e.which == 13) {

            //POST values
            var edit_template = $('#edit_template').val();
            var edit_name = $('#edit_name').val();

                $.post('ajax/name.php', {edit_name: edit_name, edit_template: edit_template}, function(data) {
                        $('div#template_edit').text(data);
                        });  

                var newContent = $(this).val();

              $(this).parent().text(newContent);
              $(this).parent().removeClass("cellEditing");
            }
    });

$(this).children().first().blur(function(){
    $(this).parent().text(OriginalContent);
    $(this).parent().removeClass("cellEditing");
});
});

});

  • 写回答

3条回答 默认 最新

  • dongyi5425 2014-10-15 22:14
    关注

    change the order of the code...

    var newContent = $(this).val();
    $(this).parent().text(newContent);
    $(this).parent().removeClass("cellEditing");
    
    var edit_template = $('#edit_template').text(); //here is not val, is text...
    var edit_name = $('#edit_name').text(); //here is not val, is text...
    
    //POST values
    $.post('ajax/name.php', {edit_name: edit_name, edit_template: edit_template}, function(data) {
       $('div#template_edit').text(data);
     });  
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错