Is there any event in javascript which can only be fired through a script and not by pointer or key actions?

时光总嘲笑我的痴心妄想 提交于 2019-12-13 06:07:34

问题


I have to get the data context passed to a table row on clicking on one of its columns in a "Reactive-table", finding no way to do this, I am wondering if there is any event which I can fire in my code on the row, but the user should not be able to do this without the code access.


回答1:


On click of any of the tds of a tr, I bubble the event to its row, add a class to the obtained element, then fire a click() event on that row, After click I remove the added class from the tr.

"click td": function(event) {
    event.stopPropagation();
    var tr = Utils.bubbleTo(event.target, "tr");
    $(tr).addClass("customClass");
    $(tr).click();
    $(tr).removeClass("customClass");
    //used the row data using, Template.instance().dict.get("data"),which is set in the next method.
},

"click .reactive-table tbody tr.customClass": function clickTr() {
    Template.instance().dict.set("data", this);
},

The reason I wanted a event which could only be fired through a script was, I didn't want users to fire the click of any of "tr" element, for which I should had written an event:

"click .reactive-table tbody tr": function clickTr() {...}

This is does not specifically answer the question,I had asked, but I solved my problem using this approach.



来源:https://stackoverflow.com/questions/36044620/is-there-any-event-in-javascript-which-can-only-be-fired-through-a-script-and-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!