我有一個插件,它包含一個插入/從數據庫中獲取數據的函數。 我的問題是我如何使用jquery或鏈接在wordpress插件中的任何其他JS。 我搜索並找到很多文章,但它不清楚,請我nead步驟添加jquery文件在我的插件。 我試過的貝爾臺階 在我的頁面頂部添加此行。在wordpress插件中使用jquery
其是我的插件代碼
和下面是位於C fn.js:\瓦帕\萬維網\測試\可溼性粉劑內容\插件\爲myplugin \ fn.js
<script type="text/javascript">
$(document).ready(function(){
<!-- ajax method to bind the dropdown menu of model-->
$("#select_brand").change(function(){
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "model.php",
data: dataString,
cache: false,
success: function(data)
{
$("#select_Model").html(data);
}
});
});
<!-- ajax method to bind the dropdown menu of city-->
$("#select_Country").change(function(){
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "city.php",
data: dataString,
cache: false,
success: function(data)
{
alert("yes");
$("#select_city").html(data);
}
});
});
});
</script>
和city.php
<?php
if($_POST['id'])
{
global $wpdb;
$id=$_POST['id'];
$query="select id,CountryCode,City from _city where CountryCode='$id'";
$result=$wpdb->get_results($query);
echo '<option selected="selected" disabled="disabled"> -- Select City -- </option>';
foreach ($result as $row)
{
$id=$row->id;
$city=$row->city;
echo '<option value="'.$id.'">'.$city.'</option>';
}
}
?>
問題的最終代碼城市下拉不能得到的值。
這聽起來像正在排隊的jQuery就好了。你在哪裏看到錯誤? – rnevius 2014-12-09 12:38:40
當我在控制檯瀏覽器中按Ctrl + Shift + J。 和代碼不工作 – Bassem 2014-12-09 12:40:31
@webeno,我已經閱讀但有些不明確 – Bassem 2014-12-09 12:41:44