简体   繁体   中英

Button click on dojo not working

Hi friends I am new to "DOJO". I tried to create a button and onclick event I want it to call a function, my code as follows

<input id="execute" type="button" value="Get Details">
require([
      "dojo/dom","dojo/on","dojo/domReady!"
    ], function(
                dom,on
    ) {

on(dom.byId("execute"), "click", execute); 

            function execute () { alert("here");}
 });

But the function execute is not calling. I tried a lot, but not working. Please help me guys.

The code itself works fine as you can see in this fiddle: http://jsfiddle.net/f7bwK/

But I'm noticing that you're not putting <script> tags around your code, is that just because you copy pasted it here, or did you really forget them? Your code should (at least) be something like:

<input id="execute" type="button" value="Get Details">
<script type="text/javascript">
    require([
      "dojo/dom","dojo/on","dojo/domReady!"
    ], function(
      dom,on
    ) {
        function execute () { alert("here");}
        on(dom.byId("execute"), "click", execute); 
    });
</script>

If you just didn't copy these, then verify if Dojo is loaded or not. Also, try and see if moving the execute() function above the on() function solves the problem.


If these solutions do not solve your problem, open your browser console (usually F12 or Ctrl + Shift + I ) and see if any error occurs.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM