我可以使用 jquery 将 html 表单元素附加到表中。如何附加用 php/my sql 查询填充的菜单,以便 php 菜单位于 td 和 input... 之间?
<script type="text/javascript">
$(document).ready(function() {
$("#link td input.rdelete").live("click", function () {
$(".newrow").attr("disabled",false);
var srow = $(this).parent().parent();
srow.remove();
});
});
function AddNew() {
if($("#link tr").length > 12) {
$(".newrow").attr("disabled",true);
}
var count = 0;
count += 1;
$("#link").append('<tr><td></td><td> <input type=\"button\" value = \"Delete\" class=\"rdelete\"/></td></tr>' );
}
</script>
php菜单是:
<select name="sub_discipline" id="sub_discipline">
<option>Select Sub-discipline...</option>
<?php
$query = mysql_query("SELECT * from sub_discipline ORDER BY sub_discipline_name ASC");
while ($row = mysql_fetch_assoc($query)){
?>
<option value="<?php echo $row['sub_discipline_pk']; ?>"><?php echo $row['sub_discipline_name']; ?></option>
<?php
}
?>
</select>
编辑:多亏了爆炸药丸,我现在有了:
<script type="text/javascript">
$(document).ready(function() {
$("#jMenu").jMenu();
$("#link td input.rdelete").live("click", function () {
$(".newrow").attr("disabled",false);
var srow = $(this).parent().parent();
srow.remove();
});
});
function AddNew() {
if($("#link tr").length > 12) {
$(".newrow").attr("disabled",true);
}
$.getJSON('../scripts/link_menu.php', function (json) {
$("#links").empty();
$.each(json, function () {
$("#links").append(new Option(this.link_title));
});
});
$("#link").append('<tr><td></td><td><select name="links[]" id="links"> </select><input type=\"button\" value = \"Delete\" class=\"rdelete\"/></td></tr>' );
</script>
问题是只有第一个附加菜单被填充。