简体   繁体   English

JavaScript内部的onclick

[英]onclick inside javascript function

I am working on a project and in this project I got the following code inside a .js file. 我正在一个项目上,在这个项目中,我在.js文件中获得了以下代码。

    // continue button (jump to next field)
    this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } );
    this._showCtrl( this.ctrlContinue );

I need to add onclick="setBrowserFrameSource(); return false;" 我需要添加onclick="setBrowserFrameSource(); return false;" to the above code. 以上代码。 I have tried: 我努力了:

cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"', cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"', But this did not work! cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"',但这没有用!

Thanks for helping. 感谢您的帮助。

Here some more code as asked in the comments: 这里是注释中要求的更多代码:

    /**
 * addControls function
 * create and insert the structure for the controls
 */
FForm.prototype._addControls = function() {
    // main controls wrapper
    this.ctrls = createElement( 'div', { cName : 'fs-controls', appendTo : this.el } );

Thanks to the answer from Rafail Akhmetshin I have changed the code to the following: 感谢Rafail Akhmetshin的回答,我将代码更改为以下代码:

        this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } );
    this.ctrlContinue.onclick = function () {
        console.log('test');
    };      
    this._showCtrl( this.ctrlContinue );

Now my instinct says I need to do something with this console.log('test'); 现在我的直觉说我需要用这个console.log('test'); But what? 但是呢 Do I need to change this into setBrowserFrameSource(); return false; 我是否需要将其更改为setBrowserFrameSource(); return false; setBrowserFrameSource(); return false; or should I add the code into the original function? 还是应该将代码添加到原始功能中?

Thanks everyone for helping. 感谢大家的帮助。

try something like this 尝试这样的事情

this.ctrlContinue.onclick = function () {
    // your code here.
};

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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