将文本从弹出表单插入到div中,并用javascript重写插入的文本
所以我在提问之前阅读了一些相关的问题,但是找不到问题的答案。希望这里的一些javascript大师能找到这个,给我带来光明 我为nicEdit创建了另一个按钮,一个视频按钮,并希望在编辑器DIV中插入一些格式化文本(注意:nicEdit有inline DIV,没有iframe,没有textarea) 这是我的按钮,从“图像”按钮重新创建:将文本从弹出表单插入到div中,并用javascript重写插入的文本,javascript,Javascript,所以我在提问之前阅读了一些相关的问题,但是找不到问题的答案。希望这里的一些javascript大师能找到这个,给我带来光明 我为nicEdit创建了另一个按钮,一个视频按钮,并希望在编辑器DIV中插入一些格式化文本(注意:nicEdit有inline DIV,没有iframe,没有textarea) 这是我的按钮,从“图像”按钮重新创建: var nicVideoOptions = { buttons : { 'video' : {name : __('Insert
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);
流程:我点击按钮,一个表单弹出,填写输入文本框,点击查询按钮,文本应该出现在编辑器DIV中
我希望我能说清楚。任何帮助都将非常感激
谢谢我真的认为我看到了你的问题。
insertcaret
函数需要一个ID,它将使用该ID执行getElementById(ID)
。看起来您正在向它传递对nicEdit对象的引用
我也建议你
您是否愿意使用像jquery这样的javascript框架?是的,如果可能的话。我自己也试过了,但运气不好。nicEdit没有将任何类或ID打印到按钮上,这一事实给我带来了困难。必须遍历,但jquery仍然无法与表单对话:(你可以控制页面吗?如果你可以,你可能可以添加你自己的nicEdit ID。哦,当然可以。我可以做任何我想做的事情:DOn nicEdit或AdvancedButton,我想我可以放置ID,比如“insert”。但是如何使它不同于提交图像按钮ID?如果我在这里添加,所有提交按钮都有相同的ID,这是不好的:new-bkElement('input')。setAttributes({'type':'submit','id':'insert'})。setStyle({backgroundColor:'#efefef',border:'1px solid#ccc',margin:'3px 0',float':'left',clear':'both'})。appendTo(this.form);尝试上面介绍的选项2。基本上只需删除函数的第一行,并将参数“areaId”的名称更改为“txtarea”.谢谢,但我几乎成功了,我放弃了该函数,使用了已经可用的函数:this.ne.selectedInstance.setContent。不过,我仍然需要更正验证。
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; }