我有問題,當我試圖平變化的功能添加到js文件的onchange我從得到它:https://www.w3schools.com/php/php_ajax_database.asp:平變化的功能添加到選定的jQuery WordPress的
jQuery(document).ready(function($) {
$('select.Nom').chosen({ width:"50%" }).change(function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","tableau.php?Nom="+str,true);
xmlhttp.send();
}
});
});
的tableau.php
:
<?php
$q = intval($_GET['Nom']);
$query = "select Adresse, Nom from herboristes where Nom = '".$q."'";
$result = mysqli_query($query);
$row = mysqli_fetch_array($result) {
echo $row['Adresse'];
}
}
?>
所以我需要的到底是當我SELCT名稱(NOM)從中我使用此代碼創造我的下拉列表中顯示的住址信息:
<select class='Nom' onchange="showUser()" name='Nom' id='Nom'>
<option value="">--- Select ---</option>
[insert_php]
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password, "somapam_bd");
$sql = mysqli_query($conn, "SELECT Nom FROM herboristes");
while($ligne_liste=mysqli_fetch_array($sql)) {
echo '<option value="'.$ligne_liste['Nom'].'">'.$ligne_liste['Nom']."</option>\n";
}
echo '</select>';
[/insert_php]
<div id="txtHint"><b>Person info will be listed here...</b></div>
我使用選定的插件WordPress的下拉列表...這是非常複雜的WordPress,我真的需要你的幫助。 謝謝
在我看來,'$( 'select.Nom')選擇({寬度: 「50%」})變化(功能showUser(STR){'看起來錯了 - 這應該是一個匿名函數,而我相信 – RamRaider
是的,但我不知道我將如何創建n anonymus函數... –