1、文本框内容为“你好!”;
2、现在要插入表情“A”,插入后,文本内容为“A你好!”;
3、现在再插入表情“B”,插入后,文本内容为“BA你好!”;
4、现在再插入表情“C”,插入后,文本内容为“CBA你好!”;我想让它变为“你好!ABC”,这个怎么改呢?
插入表情代码:
var editor = null;//输入框
var viewer = null;//显示位置
var face = null;
..........................
//=========================================================================================
// 显示表情
function viewFace()
{
face.style.visibility = "visible";
}
// 隐藏表情
function hiddenFace()
{
face.style.visibility = "hidden";
}
// 插入表情
function insertFace(img)
{
hiddenFace();
editor.focus();
editor.document.execCommand('InsertImage',false,img);
//editor.document.execCommand('Unselect');
}
//-----------------------------------
2、现在要插入表情“A”,插入后,文本内容为“A你好!”;
3、现在再插入表情“B”,插入后,文本内容为“BA你好!”;
4、现在再插入表情“C”,插入后,文本内容为“CBA你好!”;我想让它变为“你好!ABC”,这个怎么改呢?
插入表情代码:
var editor = null;//输入框
var viewer = null;//显示位置
var face = null;
..........................
//=========================================================================================
// 显示表情
function viewFace()
{
face.style.visibility = "visible";
}
// 隐藏表情
function hiddenFace()
{
face.style.visibility = "hidden";
}
// 插入表情
function insertFace(img)
{
hiddenFace();
editor.focus();
editor.document.execCommand('InsertImage',false,img);
//editor.document.execCommand('Unselect');
}
//-----------------------------------
function insertFace(img)
{
hiddenFace();
editor.focus();
editor.value = editor.value;//加这行试一试
editor.document.execCommand('InsertImage',false,img);
//editor.document.execCommand('Unselect');
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jsKmユ・/title><script>
function set11(){
document.form1.txt1.focus();
var range = document.selection.createRange();
range.moveStart( "textedit", 1 );
range.moveEnd( "textedit", 1 );
range.select();
}
</script>
</head>
<body>
<form id="form1" name="form1">
<input id="txt1" name="text1"value="sdfsdf,sdf,ede" /><br />
<input type=button onclick="set11()">
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">var editor = null;//输入框
var viewer = null;//显示位置
var face = null;//=========================================================================================
// 显示表情
function viewFace()
{
face.style.visibility = "visible";
}
// 隐藏表情
function hiddenFace()
{
face.style.visibility = "hidden";
}
// 插入表情
function insertFace(img)
{
//hiddenFace();
editor.focus();
editor.value = editor.value;
//editor.document.execCommand('InsertImage',false,img);
//editor.document.execCommand('Unselect');
}
</script>
</head>
<body>
<form name="myForm">
<div><input type="text" name="input1" value="有一段话" /></div>
<input type="button" onclick="insertFace()" value="确定" />
</form>
</body><script>
editor = document.forms["myForm"].elements["input1"];
</script>
</html>
可能是因为这句editor.document.execCommand('InsertImage',false,img);的原因
没这句文本框的焦点是在末尾的
比如:
a="x";
a="y"+a;
a="z"+a;
而JavaScript中根据document.getElementById("inputId").value就代替上边的a就可以实现的。