Binding of a dom element to a javascript variable

江枫思渺然 提交于 2019-12-31 07:06:33

问题


I'm new to js and my task is this: I've to bind a gauge object like one you can download from this rep: https://github.com/Mikhus/canv-gauge.git

to a dom element in order to get it from c++ software. How can I create my var and set it with id, just to use GetElementFromId dom method?

thank you, Daniele


回答1:


You can try it with jQuery.

Here is the example:

var elt = document.getElementById('dom-id');
jQuery.data(elt, "gauge", gaugeObject);

Be careful that the first argument of jQuery.data() is a DOM object, instead of a jQuery object.

When you want to get the binded object, use

var gaugeObject = jQuery.data(elt, "gauge");



回答2:


If you want to interact between JavaScript code and a host C++ app (like an app built with V8, CEF or Minko), you can:

  • call eval from the C++ host (for example Minko provides the AbstractDOM::eval() method) using the code provided by cipher
  • call methods specific to the C++ host implementation, for example Minko provides a two-way C++/JS messaging system described here


来源:https://stackoverflow.com/questions/29206609/binding-of-a-dom-element-to-a-javascript-variable

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