从表中传输数据

时间:2014-07-11 15:32:58

标签: javascript html css html-table

我有一个HTML表格。

<tr class="top">
  <td class="name1"><a href="#">JOHN DOE</a></td>
  <td class="company1">DOE TRUCKING</td>
  <td class="position1">TRUCKER</td>
  <td class="mc1">1234-567-8901</td>
  <td class="dot1">1234-567-8901</td>
  <td class="status1"><img src="images/cross.png" width="12" height="12" alt="cross"></td>
</tr>

当我在表格中选择名称时,会打开一个弹出窗口。

<div class="popup1">            

<div class="cross3"><a href="#"><img src="images/closr-arrow.png" width="19" height="19" alt="closr-arrow"></a></div>
    <h3>TABLE NAME</h3>
    <a href="#" class="approve">APPROVE ACCOUNT</a>
    <a href="#" class="deny">DENY ACCOUNT</a>
</div>

如何制作,以便H3保留我桌上的名字?

弹出窗口的显示方式如下:

    $(document).ready(function(){

    $('.name1 a').click(function(e) {
$('.popup1').lightbox_me({

    });

2 个答案:

答案 0 :(得分:0)

以下是jsfiddle我不知道你如何处理你的弹出窗口,但这就是你的js的结构。

$(function(){
    $('a').click(function(){
      $('h3').html($(this).html())
    });
});

答案 1 :(得分:-1)

假设当您点击<a>时弹出窗口打开,那么您可以使用$(this).text()并执行以下操作:

$(document).ready(function(){
    $('.name1 a').click(function() {
           $('.popup1 h3').text($(this).text());
        });
    });

完整示例:

<table><td class="name1"><a href="#">JOHN DOE</a></td>
          <td class="company1">DOE TRUCKING</td>
          <td class="position1">TRUCKER</td>
          <td class="mc1">1234-567-8901</td>
          <td class="dot1">1234-567-8901</td>
          <td class="status1"><img src="images/cross.png" width="12" height="12" alt="cross"></td>
</table>

<div class="popup1">
    <div class="cross3"><a href="#"><img src="images/closr-arrow.png" width="19"   height="19" alt="closr-arrow"></a></div>
    <h3>TABLE NAME</h3>
    <a href="#" class="approve">APPROVE ACCOUNT</a>
    <a href="#" class="deny">DENY ACCOUNT</a>
</div>

<script>
    $(document).ready(function(){
        $('.name1 a').click(function() {
            $('.popup1').lightbox_me({}); // <-- whatever your popup is, it plays no role here
            $('.popup1 h3').text($(this).text());
        });
    });
</script>

对不起,你说灯箱,但是我看不出它是如何被调用的,或者灯箱给出了什么样的灯箱更像是一个画廊。

这就是我使用jQueryUI对话框的原因,如果这样做无济于事,那么有人应该带走你的键盘,我希望这个也会为你节省一些重复(猜测给你的类名)。

<?php

$rows=array(
    0=>array("id"=>'1',"name"=>'Tom',"company"=>'U',"status"=>'active'),
    1=>array("id"=>'2',"name"=>'Hre',"company"=>'E',"status"=>'suspended'),
    2=>array("id"=>'3',"name"=>'Peter',"company"=>'Pawtucket',"status"=>'wasted'),
    3=>array("id"=>'4',"name"=>'Griffin',"company"=>'Patriot',"status"=>'drunk'),
);

?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

        <link href="/jquery-ui-1.10.4/css/ui-lightness/jquery-ui-1.10.4.css" rel="stylesheet">
        <script type="text/javascript" src="/jquery-ui-1.10.4/js/jquery-ui-1.10.4.js"></script>
        <style>
            .name {color:#00F;}
        </style>
        <script>
        $(document).ready(function(){    
            $("#popup").dialog({
                autoOpen: false,
                modal: true,
                width: 500,
                height: 500,
                title: "Content From Row",
                closeOnEscape: true,
                closeText: "fechar",
                show: {
                    effect: "fadeIn",
                    duration: 1000
                },
                hide: {
                    effect: "fadeOut",
                    duration: 1000
                }
            });
        });
        </script>

        <script>
            $(document).ready(function(){
                $('.name a').click(function() {
                    $('#popup h3').text($(this).text());
                    $(this).parent().siblings().each(function(){
                        if($(this).hasClass('company')){
                            $('#popup .popup_company').text($(this).text());
                        }
                        if($(this).hasClass('status')){
                            $('#popup .popup_status').text($(this).text());
                        }
                    });
                    $("#popup").dialog('open');
                });
            });
        </script>

    </head>
    <body>

        <?php 
        if(is_array($rows)){
            ?><table>
                <tr><td>Row No</td><td>ID</td><td>Name</td><td>Company</td><td>Status</td></tr>    
            <?php
            foreach($rows as $row_key=>$row){
                ?><tr><?php
                    if(is_array($row)){
                        echo('<td>'.$row_key.'</td>');
                        foreach($row as $value_key=>$value){
                            if($value_key == "name"){
                                echo('<td class='.$value_key.'><a>'.$value.'</a></td>');
                            }else{
                                echo('<td class='.$value_key.'>'.$value.'</td>');
                            }
                        }
                    }
                ?></tr><?php
            }
            ?></table><?php
        }
        ?>

        <div style="display:none;"><div id="popup">
            <div class="cross3">
                <a href="#"><img src="images/closr-arrow.png" width="19"   height="19" alt="closr-arrow"></a>
            </div>
            <h3>TABLE NAME</h3>
            <a href="#" class="popup_company"></a>
            <a href="#" class="popup_status"></a>
            <a href="#" class="approve">APPROVE ACCOUNT</a>
            <a href="#" class="deny">DENY ACCOUNT</a>
        </div></div>

    </body>
</html>