因此,在我詢問之前,我閱讀了一些相關的問題,但無法找到我的問題的答案。希望這裏的一些JavaScript大師能夠找到這個並給我帶來光明。從poput表單插入文本到div中,並用javascript重寫插入的文本
我爲nicEdit創建了另一個按鈕,一個視頻按鈕,並希望在編輯器DIV中插入一些格式化的文本(注意:nicEdit具有內聯DIV,無iframe,無textarea)。
這是我的按鈕,從圖像按鈕重建:
var nicVideoOptions = {
buttons : {
'video' : {name : __('Insert Video'), type : 'nicEditorVideoButton'} //, tags : ['VIDEO:']
},
iconFiles : {'video' : '../movie.png'}
};
var nicEditorVideoButton = nicEditorAdvancedButton.extend({
addPane : function() {
this.vi = this.ne.selectedInstance.selElm().parentTag('A');
this.addForm({
'' : {type : 'title', txt : 'Insert Video URL'},
'href' : {type : 'text', txt : 'URL', 'value' : 'http://', style : {width: '150px'}}
},this.vi);
},
submit : function(e) {
var vidVal = this.inputs['href'].value;
if(vidVal == "" || vidVal == "http://") {
alert("Enter the video url");
return false;
}
this.removePane();
if(!this.vi) {
var tmp = 'javascript:nicVidTemp();';
this.ne.nicCommand("insertVideo",tmp);
// still nothing works
//this.vi = this.findElm('VIDEO:','href',tmp);
//this.vi = this.setContent('[video:' + this.inputs['href'].value + ']');
//nicEditors.findEditor('edit-comment').setContent('<strong>Some HTML</strong> here');
//this.vi = this.setContent('<strong>Some HTML</strong> here');
insertAtCaret(this.ne.selectedInstance, vidVal);
}
if(this.vi) {
// still nothing works
//this.vi.setAttributes({
//vidVal : this.inputs['href'].value
//});
//this.vi = this.setContent('[video:' + this.inputs['href'].value + ']');
//this.vi = this.setContent('<strong>Some HTML</strong> here');
}
}
});
nicEditors.registerPlugin(nicPlugin,nicVideoOptions);
按鈕是存在的,形式poput像圖像按鈕,這樣也沒關係。但不能將文本插入到DIV中。最終輸出將從此採取:('[video:' + this.inputs['href'].value + ']')
並在編輯器DIV顯示爲:[video:http//some.com/video-url]
正如你看到的,我盲目地接觸一切:)
這插入摘自: http://www.scottklarr.com/topic/425/how-to-insert-text-into-a-textarea-where-the-cursor-is/
function insertAtCaret(areaId,text) { var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false)); if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); strPos = range.text.length; } else if (br == "ff") strPos = txtarea.selectionStart; var front = (txtarea.value).substring(0,strPos); var back = (txtarea.value).substring(strPos,txtarea.value.length); txtarea.value=front+text+back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); range.moveStart ('character', strPos); range.moveEnd ('character', 0); range.select(); } else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); } txtarea.scrollTop = scrollPos; }
流程:我點擊按鈕,彈出一個窗體,填入輸入文本框,點擊查詢按鈕後文本應該出現在編輯器DIV中。
我希望我能說清楚。任何幫助將是非常appreaciated
感謝
你開到使用JavaScript框架,像jQuery? – Benson 2010-04-30 04:14:24
是的,如果可能的話。已經嘗試過自己沒有運氣。 nicEdit沒有向按鈕打印任何課程或ID時遇到困難。不得不遍歷,但jquery仍然無法與形式:( – swan 2010-04-30 05:47:49
)有沒有控制頁面?如果你確實可以添加你自己的nicEdit ID。 – Benson 2010-04-30 06:05:01