实际上,我想在选择一个下拉列表时显示一个动态下拉列表。这是我的html:
echo '<select onchange="showcertificate(this.value);" value="'. $certificatelist .'" name=\'certificatelist\'>';
它正在调用函数 showcertificate,即:
<script type="text/javascript">
function showcertificate(vendorid)
{
var vendorid = vendorid;
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET","admin-ajax.php?action=wpt_exam_certificatelist&u="+vendorid,true);
xmlhttp.send();
<?php
if(isset($_GET["u"]))
{
$vendorid = $_GET['u'];
}
$certquery = $wpdb->get_results("SELECT * FROM wp_posts INNER JOIN wp_postmeta ON wp_posts.ID=wp_postmeta.post_id WHERE wp_posts.post_status='publish' AND wp_posts.post_type='certificate' AND wp_postmeta.meta_value='$vendorid'");
foreach($certquery as $c)
{ ?>
$("#cert").html('<option name=\'certificatelist\'><?php echo $c->post_title; ?></option>');
<?php }
?>
}
</script>
问题是 .html 函数没有在 foreach 循环内执行。如果我删除 foreach 循环,它工作正常。我已经在里面浪费了一天。请帮我。