问题
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