提取HTML中的表格行数据 [英] Extract a table row data in html

查看:60
本文介绍了提取HTML中的表格行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见下面的while循环,该循环在页面加载时显示表中的数据.

Please see the below while loop which displays the data from a table on loading of the page.

<?php 
$idcount;
$jobcount;
$flagcount;
while ( $row = sqlsrv_fetch_array ( $stmt, SQLSRV_FETCH_ASSOC ) ) 
    {
        if ($row ['Active'] == '1') {
            $flag = 'checked = "checked"';
        } else {
            $flag = '';
        }
        echo ("<tr>
            <td id = jid$idcount>".$row['JobTypeID']."</td>
            <td id = jtype$jobcount>".$row['Jobtype']."</td>
            <td align='center'><input id=active$flagcount type='checkbox' name='activecheck' $flag disabled ></td>
            <td align='center'><a class = 'toedit' href=# onclick = 'edit($idcount)'>Edit</a> | <a href=# onclick = 'dele($idcount)'>Delete</a></td>
            </tr>");
        $flag = '';
        $idcount += 1;
        $jobcount += 1;
        $flagcount += 1;
    }
    ?>

我的目的是,当我单击 Edit 链接时,我需要用相应的行数据填写表单.

My aim is that, when I click on the Edit link, I need to fill a form with the corresponding row data.

我打算在复制行中的数据后使用javascript进行处理,但是我不清楚如何为每个编辑"链接提取相应的行数据.

I am intending to use javascript to carry out the processing after the data from the row has been copied, but I am not clear about how to extract the corresponding row data for every Edit link.

我对PHP还是很陌生,所以请指导我.

I am very new to PHP, so please guide me.

以下是我正在使用的表单的代码

Below is the code of the form that I am using

<form name="job" id="ForNew" method="post"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

        <input type="hidden" id="JID" value="">

        Job Type <input type="text" id="JType"name="jobtype" value="<?php echo htmlspecialchars($JobTypeValue);?>">
        <span class="error"><?php echo $JobTypeErr;?></span><br> 

        Active? Yes <input type="radio" id = "JRadio"name="radio"<?php if (isset($ActiveValue) && $ActiveValue == "yes") echo "checked"; ?>value="yes"> 
        No <input type="radio" id ="JRadio" name="radio"<?php if (isset($ActiveValue) && $ActiveValue == "no") echo "checked"; ?>value="no"> 
        <span class="error"><?php echo $ActiveErr;?></span><br>

        <input type="submit" name="sub" value="Submit!">
    </form>

我已经如下编写函数 edit(),但是返回的值是 Object object 的形式.但是我需要的值是每个特定< td> 的ID名称,以便我可以将其值复制到表单文本框中.

EDIT 2: I have written the function edit() as follows, but the value that gets returned is in the form of Object object. But the value that I need is id name of each specific <td>, so that I can copy its value into the form textbox.

<script type="text/javascript">
function edit(Data)
{
    //Get data with reference to ID
    var Num = String(Data);
    alert("Entered Function! " + Num);
    alert("JID n Data"+$('jid'+Num));
    alert("JID value " + Num);
    alert(console.log(Num));
    $('#JID').val($('jid'+Data).html());
    $('#JType').val($('jtype'+Data).html());
    $('#JRadio').val($('active'+Data).html());
}

即使我不将 var Num = String(Data); 转换为String,我也会得到与 Object object 相同的结果.

Even if I do not convert var Num = String(Data); to String, I am getting the same result of Object object.

推荐答案

我刚刚解决了自己的问题.问题是 edit(Data)函数传递了正确的值,但是需要从 $中获取数据的元素的 id 值('#JID').val($('jid'+ Data).html()); ,未正确引用.

I just solved my own question. The problem was that the edit(Data) function was passing the correct value, but the id value of the element which needed to be taken the data from, $('#JID').val($('jid'+Data).html());, was incorrectly referenced.

语句 $('#JID').val($('jid'+ Data).html()); 必须类似于 $('#JID').val($('#jid'+ Data).html()); .缺少'jid'之前的#,它表示元素的"id"部分.

The statement $('#JID').val($('jid'+Data).html()); needs to be like $('#JID').val($('#jid'+Data).html());. The # before the 'jid' was missing, which represents the "id" part of an element.

这篇关于提取HTML中的表格行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆