我想通過腳本標記調用jQuery和PHP文件的組合,但它不能正確加載。通過腳本標記調用jquery和php文件的組合
這裏是我的代碼
<script type="text/javascript">
jQuery(document).ready(function(){
$("#country").change(function(){
var getVal = $(this).val();
<?php $sql="select t.term_id,t.description,t2.name,t2.slug from wp_term_taxonomy as t join wp_terms as t2 on t.term_id=t2.term_id where t.parent=3";
$data=mysql_query($sql);
while($rec=mysql_fetch_array($data))
{?> if(getVal=="<?php echo $rec['name'];?>")
{
window.location = "<?php echo get_category_link($rec['term_id']);?>";
} <?php }?>
});
$("#team").change(function(){
var getVal = $(this).val();
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'teams'
);
$categories=get_categories($args);
foreach($categories as $category) { ?>if(getVal=="<?php echo $category->name;?>"){
<?php $x=str_replace(' ','-',$category->name);
$y=str_replace('\'','',$x);?>
window.location = "<?php echo home_url('/');?>teams/<?php echo $y;?>";
}
<?php }?>
});
});
</script>
是否有人認爲這段代碼是不可讀的亂碼? – ThiefMaster
檢查你的JavaScript控制檯,你有任何錯誤? – frietkot
檢查控制檯後,如果沒有顯示任何錯誤,則在每個控制結構中用警報追蹤出 –