English 中文(简体)
使用 JQuery 隐藏选中的 TR
原标题:Hide selected TR using JQuery

我跟随每个行都有独有的 ID 的表格。 现在我要, 如果我单击删除链接, ID 将传递到 PHP 文件 t 从 MySQL DB 中删除记录, 然后选中的行只会隐藏 JQuery 魔法 。

<table id="projects_rec">
  <tbody>
    <tr id="MjY=">
      <td>Dany</td>
      <td><a onClick="remove( MjY= )" class="actions">Remove</a></td>
    </tr>
    <tr id="MjU=">
      <td>King</td>
      <td><a onClick="remove( MjU= )" class="actions">Remove</a></td>
    </tr>
    <tr id="MjQ=">
      <td>Test 2</td>
      <td><a onClick="remove( MjQ= )" class="actions">Remove</a></td>
    </tr>   
  </tbody>
</table>

我写过

function remove(mid){
    document.getElementById(mid).style.display= none ;
}

但是它如何将 ID 传送到 PHP 文件, 然后用 SLOW 效果隐藏 TR?

最佳回答

您可以使用 jquery 隐藏 ID :

$( #+id). hide( 慢);

假设您的 javascript 函数删除与此相似 。

remove(id)
{
  $.ajax({
    url: url here,
    type: "POST",
    data: {id : id },
    success: function(data)
    {
        var row_id = id.toString().replace(/=/g, "\=");
        $( # +row_id).hide( slow );    
    },
    error: function (xhr, textStatus, errorThrown)
    {
        alert("Error");
    }
    });
}
问题回答
<tr id="MjQ=">
  <td>Test 2</td>
  <td><a onClick="remove( MjQ= ,this)" class="actions">Remove</a></td>
</tr> 

remove 函数中

function remove(id,$this){
 //do the php stuff
 $.post( remove.php ,{id:id},function(){
   $("#"+id).hide();
 });     
}

在 php 端的 php 端上, 您可以得到 ID 作为

$id=$_REQUEST[ id ];

Working demo http://jsfiddle.net/feake/

您需要在 id 和 样本演示 中避开字符 < code/ code >, 我用 code/ code 替换为 rape < code/ code >, 宾果它有效 。

这对你们有帮助!

<强度 > 代码

function remove(row_id){
    var foo = row_id.toString().replace(/=/g, "\=");

    $("#"+foo).css( display , none );

  }​




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签