此代码在数据库中找到一个 scu 并在您键入时显示它。它适用于除 Firefox 之外的所有浏览器(chrome、IE、opera)。如果有人能明白为什么我会非常感激帮助。
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script src="chData_test.js"></script>
</head>
<body>
<form name="testForm">
<input type="text" name="scu" id="scu"><input type="button" id="theButton">
</form>
<div id="output"></div>
</body>
$(document).ready(function() {
$('#theButton').click(get);
$('#scu').keyup(get);
function get() {
$.post('data.php', {scu:testForm.scu.value}, function(output) {
$('#output').text(output).show();
});
}
});
<?php
mysql_connect("***.000webhost.com", "a9414387_***", "****");
$scu = mysql_real_escape_string($_POST['scu']);
if ($scu==NULL) {
echo "No entry scu found";
}
else {
$description = mysql_query("SELECT description FROM a9414387_***.inventory WHERE id LIKE '$scu%'");
$description_num_rows = mysql_num_rows($description);
if ($description_num_rows==0) {
echo "scu not found in database";
}
else {
$description = mysql_result($description, 0);
echo "You have selected the $description";
}
}
?>