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