本文目录一览:
- 1、你好,我想请问js动态添加文本以及文本框该怎么实现,我不想用表格做
- 2、请问哪位高手知道如何用Javascript实现文本框内的文字水平滚动
- 3、JS/JAVASCRIPT 选中文本框内的文字 让滚动条滚动到选中文字的位置
- 4、JS怎样实现用按钮控制textarea文本框的光标按行移动
- 5、怎样用javascript实现页面滚动到指定的控件
你好,我想请问js动态添加文本以及文本框该怎么实现,我不想用表格做
用easyUI属性
columns:[[
{field:'b',title:'修改',width:190,formatter:function(row){
return 'input id="sage" name ="age"';
}
]]
可以实现动态每列自动生成文本框,希望采纳。
请问哪位高手知道如何用Javascript实现文本框内的文字水平滚动
要完成此效果把如下代码加入到body区域中
SCRIPT language="javascript"
var scroll = true;
var num = 0;
function scrollStatus() {
var statusText = "";
var statusChars = new Array( 't','y','p','h','o','o','n',' ','s','t','a','r','t');
for (var l = 0; l 1; l++) {
for (var a = num; a statusChars.length; a++)
statusText += statusChars[a];
for (var b = 0; b num; b++)
statusText += statusChars[b];
}
window.status = statusText;
num++;
if (num = statusChars.length)
num = 0;
if (scroll) {
setTimeout("scrollStatus()",100);
}
}
scrollStatus();
/SCRIPT
form name="form1"
input name="stopIt" type="text" value="Stop Scrolling"
onClick=" if (scroll == false)
scroll = true;
else
scroll = false;
scrollStatus();
scrollButton();
"
/form
SCRIPT language="javascript"
var num = 0;
scrollButton();
function scrollButton() {
var buttonChars = new Array('S', 't', 'o', 'p', ' ', 'S', 'c', 'r', 'o', 'l', 'l', 'i',
'n', 'g', ' ', ' ');
var buttonText = "";
for (var a = num; a buttonChars.length; a++)
buttonText += buttonChars[a];
for (var b = 0; b num; b++)
buttonText += buttonChars[b];
num++;
if (num = buttonChars.length)
num = 0;
document.form1.stopIt.value = buttonText;
if (scroll) {
setTimeout("scrollButton();", 100);
}
}
/SCRIPT
JS/JAVASCRIPT 选中文本框内的文字 让滚动条滚动到选中文字的位置
function func(){
var textarea = document.getElementById("textarea");
//首先移动光标到所选文字位置,滚动条自动滚动
MoveCursortoPos('textarea' , 30 );
//再选中文字
textarea.setSelectionRange(30,32);//选中文本框内的文字
//textarea.scrollTop = textarea.scrollHeight;//滚动到底部
//想要修改成只滚动到 选中文字 的位置应该怎么写?
}
//设置光标位置
function MoveCursortoPos(id,pos){//定位光标到某个位置
var obj = document.getElementById(id); //获得元素
pos = pos ?pos :obj.value.length;
if (obj.createTextRange) {//IE浏览器 IE浏览器中有TextRange 对body,textarea,button有效
var range = obj.createTextRange(); //创建textRange
range.moveStart("character", pos); //移动开始点,以字符为单位
range.collapse(true);//没有移动结束点直接 折叠到一个点
range.select();//选择这个点
} else {//非IE浏览器
obj.setSelectionRange(obj.value.length, pos);
}
obj.focus();
}
JS怎样实现用按钮控制textarea文本框的光标按行移动
这个实现比较麻烦,
首先得判断内容是一行还是多行,如果是多行,那么就把光标往下移
方法是从光标位置往后搜索换行符,然后把光标移到换行符后面去
如果光标位置后面没有换行符,得插入换行符?
找到光标位置和移动光标的方法就不用展开了, createTextRange方法,去看一下文档吧
怎样用javascript实现页面滚动到指定的控件
HTML
HEAD
!-- 滚动区域坐标大小定位--
STYLE type=text/css
#divContainer {
CLIP: rect(0px 294px 20px 0px); HEIGHT: 20px; LEFT: 0px; OVERFLOW: hidden; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; WIDTH: 294px
}
#divContent {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
/STYLE
SCRIPT language=JavaScript
// 滚动开始
function verifyCompatibleBrowser(){
this.ver=navigator.appVersion
this.dom=document.getElementById?1:0
this.ie5=(this.ver.indexOf("MSIE 5")-1 this.dom)?1:0;
this.ie4=(document.all !this.dom)?1:0;
this.ns5=(this.dom parseInt(this.ver) = 5) ?1:0;
this.ns4=(document.layers !this.dom)?1:0;
this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
return this
}
bw=new verifyCompatibleBrowser()
var speed=0
var loop, timer
function ConstructObject(obj,nest){
nest=(!nest) ? '':'document.'+nest+'.';
this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
//内容宽度
this.scrollWidth=bw.ns4?this.css.document.width:this.el.offsetWidth;
//显示区域宽度
this.clipWidth=bw.ns4?this.css.clip.width:this.el.offsetWidth;
this.left=MoveAreaLeft;
this.right=MoveAreaRight;
this.MoveArea=MoveArea; this.x; this.y;
this.obj = obj + "Object";
eval(this.obj + "=this");
return this;
}
function MoveArea(x,y){
this.x=x;this.y=y
this.css.left=this.x
this.css.top=this.y
}
function MoveAreaRight(move){
//alert("this.scrollWidth="+this.scrollWidth+" objContainer.clipWidth="+objContainer.clipWidth+"\n"+" objContainer.clipWidth-this.scrollWidth="+(objContainer.clipWidth-this.scrollWidth)+"\n"+"this.x="+this.x);
document.getElementById("previous").style.display = "block";
document.getElementById("previousq").style.display = "block";
if(this.xobjContainer.clipWidth-this.scrollWidth){
this.MoveArea(this.x-move,0)
if(loop) setTimeout(this.obj+".right("+move+")",speed)
}
else{
document.getElementById("next").style.display = "none";
document.getElementById("nextq").style.display = "none";
}
}
function MoveAreaLeft(move){
document.getElementById("next").style.display = "block";
document.getElementById("nextq").style.display = "block";
if(this.x0){
this.MoveArea(this.x-move,0)
if(loop) setTimeout(this.obj+".left("+move+")",speed)
}
else{
document.getElementById("previous").style.display = "none";
document.getElementById("previousq").style.display = "none";
}
}
//滚动方法
function PerformScroll(speed){
if(initialised){
loop=true;
if(speed0) objScroller.right(speed)
else objScroller.left(speed)
}
}
//停止滚动方法
function CeaseScroll(){
loop=false
if(timer) clearTimeout(timer)
}
//初始化
var initialised;
function InitialiseScrollableArea(){
objContainer=new ConstructObject('divContainer')
objScroller=new ConstructObject('divContent','divContainer')
objScroller.MoveArea(0,0)
objContainer.css.visibility='visible'
initialised=true;
if(objScroller.scrollWidthobjContainer.clipWidth){
document.getElementById("previous").style.display = "none";
document.getElementById("next").style.display = "block";
document.getElementById("previousq").style.display = "none";
document.getElementById("nextq").style.display = "block";
}
}
// 滚动结束
/SCRIPT
/HEAD
BODY onload=InitialiseScrollableArea()
TABLE border=0 cellPadding=0 cellSpacing=0 height=300 width=360
TBODY
TR
TD background=ckh.files/a_r1_c2.jpg
!--滚动区域开始--
DIV id=divContainer style="LEFT: 50px; TOP: 50px; VISIBILITY: visible"
DIV id=divContent
nobr
但一天过去了我始终没有找到合适的配色方案但一天过去了但一天过去了我始终没有找到合适的配色方案但一天过去了但一天过去了我始终没有找到合适的配色方案但一天过去了但一天过去了我始终没有找到合适的配色方案但一天过去了
/nobr
/DIV
/DIV
!--滚动区域结束 --
/TD
/TR
!--滚动按钮开始 --
tr
td id=starttd
DIV id="previousq"
A href="javascript:;" onmouseout=CeaseScroll() onmouseover=PerformScroll(-200)
快进左
/A
/DIV
brbr
DIV id="previous"
A href="javascript:;" onmouseout=CeaseScroll() onmouseover=PerformScroll(-3)
向左
/A
/DIV
/td
td
DIV id="next"
A href="javascript:;" onmouseout=CeaseScroll() onmouseover=PerformScroll(3)
向右
/A
/DIV
brbr
DIV id="nextq"
A href="javascript:;" onmouseout=CeaseScroll() onmouseover=PerformScroll(200)
快进右
/A
/DIV
/td
/tr
!--滚动按钮结束 --
/TBODY
/TABLE
/BODY
/HTML