我在后台生成的表单中有一些下拉列表。在下拉列表中的每个选项结束时,在(括号)之间添加一些内容。我怎么能不显示这些括号及其变量内容?只留下括号前的内容。
<?php
$magazine_category_object=get_queried_object();
$magazine_category_taxonomy_slug = $magazine_category_object->slug;
$magazine_category_term_id = $magazine_category_object->term_id;
$magazine_type = 'magazine';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$magazine_args=array(
'type' => $magazine_type,
'post_status' => 'publish',
'posts_per_page' => 4,
'paged' => $paged,
'caller_get_posts' => -1,
'child_of' => 0,
'parent' => 0,
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'tax_query' => array(
array(
'taxonomy' => $magazine_category_taxonomy_slug,
'field' => 'id',
'terms' => $magazine_category_term_id
)
),
'pad_counts' => false
);
$magazine_my_query = null;
$magazine_my_query = new WP_Query($magazine_args);
if( $magazine_my_query->have_posts() )
{
while ($magazine_my_query->have_posts()) : $magazine_my_query->the_post();
$magazine_description = get_the_excerpt($post->ID);
the_title( '<h1>', '</h1>' );
if ( has_post_thumbnail() ) {
//get_the_post_thumbnail( $post->ID, array( 100, 100) );
echo get_the_post_thumbnail($post->ID,"thumbnail"); //thumbnail,medium,large,full,array(100,100)
}
echo $magazine_description;
echo '<a href="<?php echo get_permalink(); ?>">Read More...</a>';
endwhile;
}
wp_reset_query($magazine_my_query);
?>
答案 0 :(得分:2)
试试这个;
var carList=[{name:"Audi (45.000)" },{name:"Saab (40.000)"},{name:"Opel (15.000)"},{name:"Audi (45.000)"}];
var $cars=$("#cars");
$cars.empty();
carList.forEach(function(index){
$cars.append(new Option(index.name.split("(")[0].trim()))
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="cars">
</select>
适用于所有选择元素
$("select").each(function(){
var $wrapper=$(this);
var $options=$wrapper.find("option");
$wrapper.empty();
$options.each(function(index){
$wrapper.append(new Option($(this).text().split("(")[0].trim()))
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<select>
<option>Fiat (32.00)</option>
<option>Audi (12.00)</option>
</select>
<select>
<option>Bmw (32.00)</option>
<option>Tofas (22.00)</option>
</select>
<select>
<option>Dog (1.00)</option>
<option>Fish (0.00)</option>
</select>