2016-10-04 62 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;?>")';