js实现点击内容到文本框再点击更换内容 10
各位大神,我想要一个类似于下拉框的单选效果,但是是横向的,也就是说有几个内容给点击,点击一个内容,文本框会显示相应内容,点击另一个内容,文本框会显示另一个内容,希望有完整...
各位大神,我想要一个类似于下拉框的单选效果,但是是横向的,也就是说有几个内容给点击,点击一个内容,文本框会显示相应内容,点击另一个内容,文本框会显示另一个内容,希望有完整代码
展开
1个回答
展开全部
你可以参考下面的代码来进行:
<!DOCTYPE HTML>
<html>
<head>
<title>yugi</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript">
var LInserter =
{
start : 0,
end : 0,
isIE : function ()
{
return (!!window.ActiveXObject);
},
getPos : function (obj, whichone)
{
var me = LInserter;
var pos = 0;
var dir = whichone == "start" ? "StartToStart" : "StartToEnd";
if (me.isIE ())
{
var rangeSelection = document.selection.createRange ();
if (rangeSelection.parentElement ().id == obj.id)
{
if (obj.tagName.toLowerCase () == 'textarea')
{
var rangeBody = document.body.createTextRange ();
rangeBody.moveToElementText (obj);
}
else
{
var rangeBody = obj.createTextRange ();
}
for (pos = 0; rangeBody.compareEndPoints (dir, rangeSelection) < 0; pos++)
{
rangeBody.moveStart ("character", 1);
}
for ( var i = 0; i <= pos; i++)
{
if (obj.value.charAt (i) == "\n")
{
pos++;
}
}
return (pos = whichone == "start" ? (me.start = pos) : (me.end = pos));
}
}
else
{
return (pos = whichone == "start" ? (me.start = obj.selectionStart) : (me.end = obj.selectionEnd));
}
},
insert : function (obj, params)
{
var me = LInserter;
obj.value = obj.value.substring (0, me.start) + params + obj.value.substr (me.start);
return obj.value;
}
};
</script>
</head>
<body>
<a href="javascript:;" onclick="LInserter.insert(document.getElementById('conet'), '我我我我我我我我');">点我</a>
<a href="javascript:;" onclick="LInserter.insert(document.getElementById('conet'), '他他他他他他他');">点他</a>
<textarea name="conet" id="conet" rows="14" cols="50" style="resize:none;" onmouseup="LInserter.getPos(this, 'start');"></textarea>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<title>yugi</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript">
var LInserter =
{
start : 0,
end : 0,
isIE : function ()
{
return (!!window.ActiveXObject);
},
getPos : function (obj, whichone)
{
var me = LInserter;
var pos = 0;
var dir = whichone == "start" ? "StartToStart" : "StartToEnd";
if (me.isIE ())
{
var rangeSelection = document.selection.createRange ();
if (rangeSelection.parentElement ().id == obj.id)
{
if (obj.tagName.toLowerCase () == 'textarea')
{
var rangeBody = document.body.createTextRange ();
rangeBody.moveToElementText (obj);
}
else
{
var rangeBody = obj.createTextRange ();
}
for (pos = 0; rangeBody.compareEndPoints (dir, rangeSelection) < 0; pos++)
{
rangeBody.moveStart ("character", 1);
}
for ( var i = 0; i <= pos; i++)
{
if (obj.value.charAt (i) == "\n")
{
pos++;
}
}
return (pos = whichone == "start" ? (me.start = pos) : (me.end = pos));
}
}
else
{
return (pos = whichone == "start" ? (me.start = obj.selectionStart) : (me.end = obj.selectionEnd));
}
},
insert : function (obj, params)
{
var me = LInserter;
obj.value = obj.value.substring (0, me.start) + params + obj.value.substr (me.start);
return obj.value;
}
};
</script>
</head>
<body>
<a href="javascript:;" onclick="LInserter.insert(document.getElementById('conet'), '我我我我我我我我');">点我</a>
<a href="javascript:;" onclick="LInserter.insert(document.getElementById('conet'), '他他他他他他他');">点他</a>
<textarea name="conet" id="conet" rows="14" cols="50" style="resize:none;" onmouseup="LInserter.getPos(this, 'start');"></textarea>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询