2017-04-08 41 views
0

我想獲得ID和複選框的狀態(我有CSS的按鈕CSS Button複選框數據綁定返回兩個值?

按鈕的名稱,並積極

<div class="onoffswitch"> 
<input type="checkbox" data-bind="checked: ioValue" class="onoffswitch-checkbox" id="io1"> 
    <label class="onoffswitch-label" for="io1"> 
    <span class="onoffswitch-inner"></span> 
    <span class="onoffswitch-switch"></span> 
</label> 

按鈕作品和展示真假,我無法弄清楚如何獲得ID

self.ioEvent = function(data, event) { 
      console.log(1) 
      console.log(data) 

      console.log(data[0]) 
      console.log(data[1]) 

      $.ajax({ 
       type: "GET", 
       dataType: "json", 
       data: {"io": data[0], "status": data[1]}, 
       url: "/plugin/test/setIOcheckbox",  
       async: false 
     }); 
    } 
+0

FYI想做一個插件Octoprint –

回答

1

event.target.id應該給你的「ID」

+0

不工作...無法讀取屬性「目標」 –

+0

改變代碼,並得到使用event.target.id –