seajs中怎么去实现 <a href='javascript:xxx()'></a>

leon_rock 发布于 2013/12/27 13:42
阅读 829
收藏 1

seajs 刚学习,请指教~

加载中
0
__FresHmaN
__FresHmaN
in app.js
define('app', [], function(require, exports, module){
    var sayHello = function() {
        alert('hello');
    };
    //u can expose the sayHello func here or not
    exports.sayHello = sayHello;
});

//in use
seajs.use('app', function(app){
   //just expose the method in here
    window.sayHello = app.sayHello;    
});

//so, u can do like your code
<a href='javascript:sayHello();'>say hello</a>

this is my solution. I'm also new to seajs.We can discuss.
0
__FresHmaN
__FresHmaN
export the method to global. Then you can do like this.
leon_rock
leon_rock
example plz
0
leon_rock
leon_rock

引用来自“多萨穆大叔”的答案

in app.js
define('app', [], function(require, exports, module){
    var sayHello = function() {
        alert('hello');
    };
    //u can expose the sayHello func here or not
    exports.sayHello = sayHello;
});

//in use
seajs.use('app', function(app){
   //just expose the method in here
    window.sayHello = app.sayHello;    
});

//so, u can do like your code
<a href='javascript:sayHello();'>say hello</a>

this is my solution. I'm also new to seajs.We can discuss.
It works
返回顶部
顶部