0
我正在使用的嘗試下面的代碼從頁面發送行數據到一個模式窗口:發送數據屬性模態
<?php
$select = "SELECT * FROM table";
$res = mysql_query($select) or die();
echo "<div>"
echo "<table>"
echo "<tr><th>Edit/Delete</th>
<th>Group</th>
<th>Type</th>
<th>Service</th>
<th>Description</th>
</tr>";
while(($Row = mysql_fetch_assoc($res)) !== FALSE){
echo "<tr><td>
<a href='' class='open-EditRow btn btn-primary' value='Edit'
data-des=\"{$Row[description]}\"
data-group=\"{$Row[resgroup]}\"
data-type=\"{$Row[restype]}\"
data-service=\"{$Row[service]}\">Edit</a>
</td>";
echo "<td>{$Row[resgroup]}</td>";
echo "<td>{$Row[restype]}</td>";
echo "<td>{$Row[service]}</td>";
echo "<td>{$Row[description]}</td></tr>\n";
};
echo "</table>";
echo "</div>";
if(mysql_num_rows($res) == 0){
echo "No Results";
}
}
?>
正如你可以在上面的標籤看,我使用獲取行數據的數據屬性,其中包括resgroup,restype,service和description。在這一點上,我可以打開沒有問題的模式窗口。
的JavaScript我使用看起來像這樣:
<script type="text/javascript">
$(function()
{
$('.open-EditRow').click(function(e){
e.preventDefault();
$group = $(this).attr('data-group');
$type = $(this).attr('data-type');
$service = $(this).attr('data-service');
$descript = $(this).attr('data-description');
console.log($group);
console.log($type);
console.log($service);
console.log($descript);
});
});
</script>
我可以做一個警報($組)和數據組的行數據確實出現在警報窗口。
我的模態窗口有一個輸入標籤的表單,我試圖填充數據屬性。輸入標籤具有與數據屬性本身同名的類,名稱和標識。
我知道我不需要使用console.log();但我不知道如何傳遞數據比警報窗口更遠。
在我的JavaScript,在那裏我會申請$( '#組')VAL($組)。 ? – HoodCoderMan
謝謝,先生。這工作。我很欣賞它。 – HoodCoderMan
沒問題,祝你好運。 –