2012-11-21 82 views
1

嗨,我有一個工作響應選擇菜單,我想能夠使只是其中一個鏈接,_blank響應選擇菜單目標_blank

<select onchange="if (this.value) window.location.href = this.value;"> 

    <option value="" selected="selected">Navigation</option> 
    <option value="#">Home</option> 
    <option value="lessons/">Lessons</option> 
    <option value="locations/">Locations</option> 
    <option value="accomodation/">Accommodation</option> 
    <option value="holidays/">Holidays</option> 
    <option value="shop/">Shop</option> 
    <option value="contact/">Contact</option> 
    <option value="kite-jobs/">Jobs</option> 

</select> 

回答

0

目標上使用window.open()的情況下,你想:

<select onchange="if (this.value === 'accomodation') window.open(this.value, '_blank') else if (this.value) window.location.href = this.value;"> 
+0

我無法使這項工作,我想利用THI在Shop鏈接上它必須打開一個cnamed網址,也就是http://shop.website.com –

+0

然後把'http:// shop.website.com'放在值中。 – Barmar

0
<select> 

    <option value="" selected="selected">Navigation</option> 
    <option value="#">Home</option> 
    <option value="lessons/">Lessons</option> 
    <option value="locations/">Locations</option> 
    <option value="accomodation/">Accommodation</option> 
    <option value="holidays/">Holidays</option> 
    <option value="shop/">Shop</option> 
    <option value="contact/">Contact</option> 
    <option value="kite-jobs/">Jobs</option> 

</select> 
$(function(){ 
    $('select').on('change', function() { 
     var url = this.value; 
     if(url == 'shop/'){   // or whatever 
     window.open(url, '_blank'); 
     }else{ 
     window.location.href = url; 
     }  
    }); 
}); 
+0

這與工作非常接近,但是Chrome會彈出窗口阻止新窗口,並且新窗口鏈接在Safari移動版中無法使用。 –