【发布时间】:2014-07-24 13:29:18
【问题描述】:
我正在使用以下代码尝试将行数据从页面发送到模式窗口:
<?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";
}
}
?>
正如您在上面的 a 标签中看到的,我使用 data-attributes 来获取行数据,其中包括 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>
我可以做一个警报($group),数据组的行数据确实出现在警报窗口中。
我的模态窗口有一个带有输入标签的表单,我试图用数据属性填充它。输入标签具有与数据属性本身同名的类、名称和 id。
我知道我不需要使用 console.log();但我不知道如何在警报窗口之外传递数据。
【问题讨论】:
标签: javascript php jquery html