2016-07-23 39 views
0

我需要在總部設在空間顯示/隱藏控件幫助的隱形我點擊管理的可視性和widget

我使用的日期選擇控件的自舉和其他一些小部件

我的代碼是:

<div class="o_datepicker"> 

      <t t-set="placeholder" t-value="widget.getParent().node and widget.getParent().node.attrs.placeholder"/> 
      <input type="text" 
       t-att-name="widget.name" 
       t-att-placeholder="placeholder" 
       class="oe_datepicker_master oe_simple_date"/> 
     <input t-att-id="widget.name" type="text" 
       t-att-placeholder="placeholder" 
       class="oe_hijri oe_datepicker_master" 
       /> 
    </div> 

當我點擊在divdiv引導日期選擇器小部件是可見的..我想限制到第一個輸入,當我點擊第二個輸入時,小部件應該是不可見的,因爲有另一個小部件,我點擊th第二個輸入。

注:兩個輸入必須在同一<div class="o_datepicker">

感謝

+0

爲什麼你不把兩個輸入放在同一個div中,它會簡化你的code.is有什麼特別的理由把兩個輸入放在同一個div中? – mean

+0

是的..還有一些其他的東西需要處理,他們必須在同一個div –

回答

1

你必須在第二輸入點擊停止事件傳播:

$(".o_datepicker input:last").click(function(event) { 
    //Prevents the event from bubbling up the DOM tree, 
    //preventing any parent handlers from being notified of the event. 
    event.stopPropagation(); 
    //Your code here. 
}); 

我希望這會幫助你。

+0

謝謝我的朋友,你能否更多地向我解釋代碼? –

+1

當然可以!當您單擊第二個輸入時,事件會冒泡到父元素並觸發每個點擊處理程序。因此,當您單擊第二個輸入時,父DIV也會收到點擊!上面的代碼將阻止!讓我知道這是否能解決您的問題。 –