2014-01-24 23 views
0

因此,我正在處理一些簡碼,當我單擊簡碼按鈕時,我顯示帶有可用簡碼的選擇框的thickbox窗口。當我從下拉列表中點擊短代碼時,我會顯示短代碼選項。問題是當我從選擇中選擇不同的短代碼時,它顯示新的短代碼選項和以前的短代碼選項。我想要移除thickbox,然後用新的選定div顯示thickbox。TB_inline? onclick刪除thickbox然後顯示thickbox和div id從選項值

<script> 
    function inlineId() { 
    tb_remove(); 
    var optionValue = jQuery('select[name=shortcodeOptions]').val() 
    tb_show("Choose a Shortcode", "#TB_inline?height=300&amp;width=400&amp;inlineId=" + optionValue + ""); 
    } 
</script> 

<div id="shortcode_list" style="display:none"> 
    <label for="select"> 
     <span>Choose a shortcode</span> 
    </label> 
    <select name="shortcodeOptions"> 
     <option>Select a shortcode</option> 
     <option onclick="inlineId()" value="alert_div">Alert</option> 
     <option onclick="inlineId()" value="button_div">Button</option> 
    </select> 
</div> 

有了這個代碼,當我選擇了新的選項,我可以看到的ThickBox關閉而改變的同時所選擇的選項,但它關閉之後,在沒有顯示的ThickBox。

回答

1

我對此有不同的看法。不知道這是否是最好的解決方案,但它的工作。

<script> 
function showOptions() { 
    var optionValue = jQuery('select[name=shortcodeOptions]').val()  
    jQuery('.sc_options').css('display','none'); 
    jQuery('.'+optionValue+'').css('display','block'); 
    tb_show("Choose a Shortcode", "#TB_inline?height=300&amp;width=400&amp;inlineId=" + optionValue + ""); 
} 
</script> 

和HTML內容

<div id="shortcode_list" style="display:none"> 
    <label for="select"><span>Choose a shortcode</span></label> 
    <select name="shortcodeOptions" onchange="showOptions();"> 
     <option> 
      Select a shortcode 
     </option> 

     <option value="alert_div"> 
      Alert 
     </option> 

     <option value="button_div"> 
      Button 
     </option> 
    </select> 
</div>