下面是一個對話框中的javascript文件確定按鈕的代碼:如何在不按Javascript中的相關按鈕的情況下自動執行按鈕的某些操作(OK/SUBMIT)?
onOk: function() {
var selection = this._.editor.getSelection(),
bookmarks = selection.createBookmarks();
var cells = this.cells;
for (var i = 0; i < cells.length; i++)
this.commitContent(cells[ i ]);
this._.editor.forceNextSelectionCheck();
selection.selectBookmarks(bookmarks);
this._.editor.selectionChange();
},
在這裏,我需要按確定按鈕爲我的文本區域:
commit: function(element) {
var value=20;
unit = this.getDialog().getValueOf('info', 'widthType') || getCellWidthType(element);
element.setStyle('width', value + unit);
},
現在,我希望ok按鈕的操作可以在不按ok按鈕的情況下執行。
所以,使用的功能自調用函數並執行它裏面的犯這樣的:
commit: function(element) {
var value=20;
unit = this.getDialog().getValueOf('info', 'widthType') || getCellWidthType(element);
(function() {
var selection = this._.editor.getSelection(),
bookmarks = selection.createBookmarks();
var cells = this.cells;
for (var i = 0; i < cells.length; i++)
this.commitContent(cells[ i ]);
this._.editor.forceNextSelectionCheck();
selection.selectBookmarks(bookmarks);
this._.editor.selectionChange();
})();
element.setStyle('width', value + unit);
},
但它無法正常工作。
無論如何,onOK
裏面的代碼每次都會自動執行嗎?
,,,這樣不行。你還有其他解決方案嗎?我也嘗試了更改jQuery的方法..但它也失敗.. –
請檢查我更新的答案,如果您使用jQuery,那麼這將爲你工作。 –