Ext.onReady(function() {
Ext.create('Ext.panel.Panel', {
bodyPadding : 5, // Don't want content to crunch
// against the borders
width : 300,
title : 'Filters',
items : [{
xtype : 'textareafield',
id : 'content',
fieldLabel : 'content'
}],
buttons : [{
xtype : "button",
text : "订单号",
style : {
marginLeft : '20px'
},
handler : function() {
var o = Ext.getCmp("content");
o.focus();
var value = "{Tradeoid}";
insertValue(o, value);
}
}],
renderTo : Ext.getBody()
});
//插入方法
function insertValue(el, value) {
if (el.inputEl.dom.setSelectionRange) {
var withIns = el.inputEl.dom.value.substring(0,
el.inputEl.dom.selectionStart)
+ value;// 获取光标前的文本+value
var pos = withIns.length;// 获取光标前文本的长度
el.inputEl.dom.value = withIns
+ el.inputEl.dom.value.substring(
el.inputEl.dom.selectionEnd,
el.inputEl.dom.value.length);// 光标前文本+获取光标后文本
el.inputEl.dom.setSelectionRange(pos, pos);// 设定光标位置
} else if (document.selection) {
document.selection.createRange().text = value;// 获取激活文本块
}
}
});