我在这里看到了许多类似的问题,这些问题已经解决了,但是我无法弄清楚为什么我的代码会产生此错误:editRow()未定义,因为我已经遵循了其他所有问题。我想打开一个弹出窗口,以在php的crud表中编辑一行。我试图将函数放在文件的开头,但是没有任何变化。
<!DOCTYPE HTML PUCLIC "-//W3C//DTDHTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>LIBRARY DATABASE</TITLE>
<link rel="stylesheet" type="text/css" href="tablestyle.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
var newObj = {
width: 900,
height: 460,
editable: false,
pageModel: { type: "local", rPP: 15, rPPOptions: [10, 15, 20, 50, 100] },
flexHeight: true,
title: "Companies listed on the <b>NASDAQ</b>",
freezeCols: 1,
resizable: true,
editModel: { clicksToEdit: 2 },
selectionModel: { mode: 'single', type: 'row' }
};
var $grid = $("#grid_crud").pqGrid(newObj);
//create popup dialog.
$("#popup-dialog-crud").dialog({ width: 400, modal: true,
open: function () { $(".ui-dialog").position({ of: "#grid_crud" }); },
autoOpen: false
});
function getRowIndx() {
var arr = $grid.pqGrid("selection", { type: 'row', method: 'getSelection' });
if (arr && arr.length > 0) {
return arr[0].rowIndx;
}
else {
alert("Select a row.");
return null;
}
}
function editRow() {
var rowIndx = getRowIndx();
if (rowIndx != null) {
var row = $grid.pqGrid('getRowData', {rowIndx: rowIndx});
var $frm = $("form#crud-form");
$frm.find("input[name='memberID']").val(row[0]);
$frm.find("input[name='MFirst']").val(row[1]);
$frm.find("input[name='MLast']").val(row[3]);
$frm.find("input[name='Street']").val(row[4]);
$frm.find("input[name='number']").val(row[5]);
$frm.find("input[name='postalCode']").val(row[6]);
$frm.find("input[name='Mbirthdate']").val(row[7]);
$("#popup-dialog-crud").dialog({ title: "Edit Record (" + (rowIndx + 1) + ")", buttons: {
Update: function () {
//update row.
var row = [];
row[0] = $frm.find("input[name='memberID']").val();
row[1] = $frm.find("input[name='MFirst']").val();
row[3] = $frm.find("input[name='MLast']").val();
row[4] = $frm.find("input[name='Street']").val();
row[5] = $frm.find("input[name='number']").val();
row[6] = $frm.find("input[name='postalCode']").val();
row[7] = $frm.find("input[name='Mbirthdate']").val();
$grid.pqGrid('updateRow', { rowIndx: rowIndx, row: row, checkEditable: false });
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
}).dialog("open");
}
}
</script>
</HEAD>
<div class="navbar">
<a href="mydatabase.php">Home</a>
<a href="member_table.php">Member</a>
<a href="book_table.php">Book</a>
<a href="borrows_table.php">Borrows</a>
</div>
<br><br>
<div class="navbar">
<a href="insert.php">Insert</a>
<a href="update.php">Update</a>
<a href="delete.php">Delete</a>
</div>
<TABLE class="minimalistBlack">
<thead>
<tr>
<th> memberID </th>
<th> First Name </th>
<th> Last Name </th>
<th> Street </th>
<th> Number </th>
<th> Postal Code </th>
<th> Birthdate </th>
<th> Update </th>
</tr>
</thead>
<?php
$conn= mysqli_connect("localhost","root","","library");
if ($conn -> connect_error){
die("Conenction failed:". $conn->connect_error);
}
$sql="SELECT memberID,MFirst,MLast,Street,number,postalCode,Mbirthdate FROM member";
$result = $conn->query($sql);
if ($result->num_rows>0){
while($row= $result->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['memberID']."</td>";
echo "<td>".$row['MFirst']."</td>";
echo "<td>".$row['MLast']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['number']."</td>";
echo "<td>".$row['postalCode']."</td>";
echo "<td>".$row['Mbirthdate']."</td>";
echo "<td><a href='#' onclick='editRow()'>Edit </a>
| <a href=\"deletefmtable.php?memberID=$row[memberID]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";
}
echo "</TABLE>";
}
else { echo "0 result"; }
$conn->close();
?>
</TABLE>
</HTML>
答案 0 :(得分:0)
不确定,但是您的文档没有<body>
标记,因此很可能是个问题。
您还需要将jquery脚本和自定义js的加载分开。所以:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>//Your custom scripts</script>
答案 1 :(得分:0)
您不能将脚本代码放在具有<script>
属性的src
标记内。您需要两个单独的标签,一个用于加载jQuery
,另一个用于加载脚本。
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
... your code here
</script>