2016-10-04 61 views
0

我正在尝试从列“操作”中的按钮传递信息到模态div,我使用JS调用模式,但我不确定如何从表中发送信息到div。 (记住它必须对每个按钮不同的信息,因为每个按钮是另一行)如何通过jQuery传递信息

<?php 
error_reporting(0); 
    $con = new mysqli("localhost","****","****","****");  
if(mysqli_connect_errno()){   
echo(mysqli_connect_error());  
} 
$cuser = $_COOKIE['c_user']; 

$result = $con->query("SELECT * FROM calls");  
echo" 

<table class=\"table table-bordered responsive\"> 
     <thead> 
      <tr> 
       <th width=\"5%\">#</th> 
       <th>Call Status</th> 
       <th>Player ID</th> 
       <th>Player Name</th> 
       <th width=\"33%\">Actions</th> 
      </tr> 
     </thead> 
<tbody>";    
    while($row = $result->fetch_assoc()){ 
            echo "<tr> ";  
             echo("<td>" . $row['id'] . "</td> "); 
             echo("<td>" . $row['status'] . "</td> "); 
             echo("<td>" . $row['pid'] . "</td> "); 
             echo "<td>" . $row['pname'] . "</td> "; 
       echo "<td> "; 
            if($row['status'] == 'Pending'){ 
             echo "<a button type=\"button\" class=\"btn btn-warning\" href=\"calls.php?claim=true&callid=$row[id]\">Claim Call</button /a> "; 
            } else if($cuser == $row['claimedby']) { 
             echo "<a button type=\"button\" class=\"btn btn-danger\" href=\"calls.php?closecall=true&callid=$row[id]\">Close Call</button /a> "; 
            } else { 
                          echo "<a button type=\"button\" class=\"btn btn-warning disabled\">Claimed</button /a> "; 
            } 
            echo "<a button type=\"button\" href=\"javascript:;\" onclick=\"jQuery('#modal-2').modal('show');\" class=\"btn btn-info\">Call Info</button /a> "; 
            echo "<a button type=\"button\" id = $row[id] href=\"javascript:;\" onclick=\"jQuery('#modal-1').modal('show');\" class=\"btn btn-success\">Server Info</button /a> "; 
            echo "<a button type=\"button\" class=\"btn btn-primary\">Join Server</button /a> "; 
             echo "</td> "; 
} 
      echo "</tr> 
     </tbody> 
    </table>"; 

echo"<div class=\"modal fade\" id=\"modal-1\"> 
<div class=\"modal-dialog\" style=\"width: 50%\"> 
    <div class=\"modal-content\"> 

     <div class=\"modal-header\"> 
      <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">&times;</button> 
      <h4 class=\"modal-title\">Call Info</h4> 
     </div> 

     <div class=\"modal-body\" id=\"serverHandle\"> 

     </div> 

     <div class=\"modal-footer\"> 
      <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button> 
     </div> 
    </div> 
</div> 
</div>"; 
    ?> 
+0

是否使用引导的模式? –

+0

@NorlihazmeyGhazali我在代码中包含了模式,它的自定义。 –

+0

@ICostaExDesigns:当有人点击这些按钮时,您是否想将任何类型的信息从按钮发送到模式DIV? – mi6crazyheart

回答

0

你想从按钮到模态DIV发送任何类型的信息,当有人点击这些按钮?如果你想要的话,你可以添加一个自定义属性到你的按钮,就像这个<button info='my-info' id=''>Click</button>然后当有人点击该按钮时,你可以通过使用JavaScript从该属性中提取值this &通过使用来自Modal DIV的任何ID 。

0

你可以添加类似这样的东西到你的按钮以及一个点击事件。

 data-value="<?php echo $Something->SomeValue;?>" 

然后,当点击事件被触发,你可以得到的价值是这样的:

$(this).data("value"); 

您可以使用各种数据 - [标签]通过多条信息。

或作为备选,将它添加到每个按钮:

onclick='someFunction("<?php echo $Something->SomeValue;?>")';