0
我有一個容器列表,我想添加一個按鈕,在容器上顯示終端,點擊終端標識。 如何獲得我們點擊哪個元素的索引
但我不知道如何捕捉列表中容器的索引。
我的HTML是:
<li class="liContainer">
<div>
<h3>{{nameContainer}}</h3>
</div>
<div id="idContainer">
<span>ID: {{idContainer}}</span>
</div>
<div id="stateContainer">
<span class="state">State: {{stateContainer}}</span>
</div>
<div id="terminalContainer" class="hidden">
<div class="terminal hidden"></div>
</div>
<button type="button" class="stop {{#if to_hide_stop}}hidden{{/if}}"> </button>
<button type="button" class="start {{#if to_hide_start}}hidden{{/if}}"> </button>
<button type="button" class="pause {{#if to_hide_pause}}hidden{{/if}}"></button>
<button type="button" class="unpause {{#if to_hide_unpause}}hidden{{/if}}"> </button>
<button type="button" class="cmdLogs"> terminal </button>
</li>
而我的JS:
'click .cmdLogs'(event) {
Session.set("displayCmdLogs",true);
//here I need to do something to get the ID with the event and then I could do...
setTimeout(function(){
var term = new Terminal();
console.log("term: " + term);
//.. the getElement on the right one
term.open(document.getElementsByClassName('terminal')[idFromEvent]);
//term.fit();
term.write('Hello from container.js');
},200);
}
權,遺憾的錯誤 – Jerome
通過獲取點擊的元素[MeteorJS:如何獲得點擊的元素(HTTP ://stackoverflow.com/questions/35194509/meteorjs-how-to-get-clicked-element)和單擊元素的索引使用[獲取jQuery集合中單擊元素的索引](http://stackoverflow.com /問題/ 5545283/GET-指數的-點擊元素,在收集與 - jQuery的)。使用'$(event.currentTarget).closest('li').index();' – Tushar
@Tushar是否可以做.closet('className')? – Jerome