[英]onclick inside javascript function
我正在一個項目上,在這個項目中,我在.js文件中獲得了以下代碼。
// continue button (jump to next field)
this.ctrlContinue = createElement( 'button', { cName : 'fs-continue', inner : 'Continue', appendTo : this.ctrls } );
this._showCtrl( this.ctrlContinue );
我需要添加onclick="setBrowserFrameSource(); return false;"
以上代碼。 我努力了:
cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"',
cName : 'fs-continue' . 'onclick="setBrowserFrameSource(); return false;"',
但這沒有用!
感謝您的幫助。
這里是注釋中要求的更多代碼:
/**
* 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 } );
感謝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 );
現在我的直覺說我需要用這個console.log('test');
但是呢 我是否需要將其更改為setBrowserFrameSource(); return false;
setBrowserFrameSource(); return false;
還是應該將代碼添加到原始功能中?
感謝大家的幫助。
嘗試這樣的事情
this.ctrlContinue.onclick = function () {
// your code here.
};
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.