Adding a component to html table via Javascript API
I have a 3rd party component that I need to add to a menu bar on our web page. The menu bar is an html table with one row of cell's, each cell is a link and I need to add another cell that contains this com开发者_JAVA百科ponent. I have been given a Javascript api from the developer of the component. I can easily add another cell to the menu bar, but how do I add this component to the table. Obviously I am not an experienced html/Javascript developer so please excuse my lack of knowledge.
Is your question how to let the component do its stuff when a visitor clicks on this new cell? In case of yes, your html should look basically like this:
<td onclick="component.doStuff()">Click me</td>
However, my answer will get downvoted, because it is bad practice. So here's another approach:
<td id="myCell">Click me</td>
<script>
document.getElementByID("myCell").onclick = component.doStuff;
</script>
The latter gives you the possibility to place the code where ever your (complex) framework it requires.
精彩评论