I have html markup like this
<button id="button1" onclick="alert='yup'"></button>
and I want to make a button widget using that DOM as an anchor
var button = new Button({label: "button"}, "button1")
How do I copy onclick attribute into button widget ? The reason I want to do this because web-framework I used (lift) add some function to button before I make it into dijit widget.
PEM is absolutely correct, use dojo parser for that (the keyword for onclick will then be with capital 'C' : "onClick='alert(true)'" or "data-dojo-props='onClick:function() {alert(true)}' ".
Anyways, here's one way to achieve it
var dom = dojo.byId('button1');
var fn = eval(dom.onclick.toString());
dom.onclick = null;
var button = new Button({label: "button", onClick:fn}, "button1");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.