2014-02-28 118 views
0

我有一個模態窗口,裏面有一個選擇。 模式工作正常,但選擇只能使用一次。 問題是什麼?jquery模式選擇問題

這是我的js。

$s = jQuery.noConflict(); 
$s(document).ready(function() { 

//Display the modal 
$s('#att-add').on('click', function (e) { 
    e.preventDefault(); 
    $s.fn.custombox(this, { 
     overlay: true, 
     effect: 'fadein', 
     eClose: '.close' 
    }); 
    $s('select').selectric(); 
}); 
}); 

對於我使用Selectric的選擇框。

這是我的HTML模態窗口

<div id="modal" style="display: none;" class="modal-content"> 
    <div class="modal-header"> 
     <button type="button" class="close" title="inchide">&times;</button> 
     <h3>Adauga un atribut nou</h3> 
    </div> 
    <div class="modal-body"> 
     <div class="form-group"> 
     <label>Numele atributului</label> 
     <input type="text" name="name" atocomplete="off" /> 
     </div> 
     <div class="form-group"> 
     <label>Selectati grupul de atribute</label> 
     <select name="groups" class="select"> 
      {section name=op loop=$groups.attribute_group_id} 
      <option value="{$groups.attribute_group_id[op]}">{$groups.name[op]}</option> 
      {/section} 
     </select> 
     </div> 
     <div class="form-group"> 
     <label>Ordinea</label> 
     <input class="ordine" type="text" name="ordine"/> 
     </div> 
    </div> 
</div> 
+0

當你說「只選擇一次作品」時,你的意思是selectric只在第一次打開模式時才應用?那麼當你關閉模式並再次打開它時,它不會被應用?你是否在控制檯中發現錯誤?你能包含你的HTML嗎? –

+0

我已經包含它 – ciprian2301

+0

您使用模板嗎?問題是模板不起作用,或者電氣造型沒有被應用? –

回答

0

我認爲問題是,當selectric適用它的造型,它消除了select元素和裏面的模板。你可能需要做的是傳遞一個回調的customboxclose財產破壞selectric當用戶關閉模式:

$s = jQuery.noConflict(); 
$s(document).ready(function() { 

    //Display the modal 
    $s('#att-add').on('click', function (e) { 
     e.preventDefault(); 
     $s.fn.custombox(this, { 
      overlay: true, 
      effect: 'fadein', 
      eClose: '.close', 
      close: function() { $s('select').selectric('destroy'); } 
     }); 
     $s('select').selectric(); 
    }); 
}); 

這是未經測試,我無法輕鬆地重現該問題。

+0

是的,這很好,它的工作 – ciprian2301

1

我不熟悉的Selectric但我猜有可能是因爲你是初始化同樣選擇的每次點擊。嘗試在點擊功能之外移動$s('select').selectric();行。

$s = jQuery.noConflict(); 
    $s(document).ready(function() { 

    $s('select').selectric(); 

    //Display the modal 
    $s('#att-add').on('click', function (e) { 
     e.preventDefault(); 
     $s.fn.custombox(this, { 
      overlay: true, 
      effect: 'fadein', 
      eClose: '.close' 
     }); 
    }); 
    });