代码:
//querying the campaigns
$campaigns = $wpdb->get_results(
"SELECT *
FROM tbl_campaigns
ORDER BY campaignID DESC",
OBJECT_K
);
//displaying the campaigns
<select name="campaign_list" class="campaign_dropdown">
<?php
foreach($campaigns as $c):
echo '<option value="'.$c->campaignID.'" rel="'.$c->campaignID.'">'.$c->campaign_name.'</option>';
endforeach;
?>
</select>
//javascript/jquery
var $j = jQuery.noConflict();
$j('.campaign_dropdown').change(function(){
if($j(this).val() != '0'){
var rel = $j(this).closest('option').attr('rel');
alert(rel);
}
});
我想要做的只是在我从下拉列表中选择时显示 rel 值。但我总是得到一个未定义的消息。(如果这将得到修复,每当我从下拉列表中选择时,我都会使用它来加载另一个页面)
代码有什么问题?