2016-01-19 89 views
0

嗨,我發現這些開/關flipswitches https://proto.io/freebies/onoff/將生成CSS3開/關flipswitches動畫過渡。如何讓開/關FlipSwitch觸發功能

使用Google Apps腳本/插件的我使用了我的客戶端上的CSS + HTML。 我希望它在切換時觸發一個功能,在&關閉都應該觸發相同的功能。 enter image description here

簡單的按鈕:

enter image description here

這是一個簡單的按鈕是怎麼做的現在:

客戶端:

<button onclick="google.script.run.insertTextToCellA();" id="ButtonA">Button A</button> 

而且這三ggers我服務器端功能:

function insertTextToCellA(){ 
var cellA = table.getRow(1).getCell(2).getChild(0); 
    cellA.setText('Hello Testing!');   
    } 
} 

這是我的代碼看起來像開關按鈕

<div class="onoffswitch"> 
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked> 
    <label class="onoffswitch-label" for="myonoffswitch"> 
     <span class="onoffswitch-inner"></span> 
     <span class="onoffswitch-switch"></span> 
    </label> 
</div> 

問題:我沒有任何的 'onClick'與此開關按鈕,我怎樣才能讓它在觸發我的服務器端功能?

回答

2

您可以將onclick事件綁定到任何HTML元素。

<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" onclick="google.script.run.insertTextToCellA();" checked/> 

JSFiddle Example

+0

工作就像一個魅力,謝謝大衛! –