尝试更改 javascript 中的文本位置
Trying to change the text position in javascript
我正在 html 中制作四个按钮 ( input type="button"
),并希望它们在单击时运行功能,但没有任何反应。
HTML 代码是:
<div id="newtext" style="position:absolute; top:100px;">
<p>this is Text</p>
</div>
<form>
<input type="button" name="moveLayer" value="move Left" onclick="move('left');">
<input type="button" name="moveLayer" value="move Right" onclick="move('right');">
<input type="button" name="moveLayer" value="move Up" onclick="move('up'); ">
<input type="button" name="moveLayer" value="move Down" onclick="move('down'); ">
</form>
脚本是:
function move(direction) {
var layerText = document.getElementByID("newtext");
switch(direction) {
case "left":
layerText.style.left=50;
break;
case "right":
layerText.style.right=150;
break;
case "up":
layerText.style.up=50;
break;
case "down":
layerText.style.down=150;
break;
default:
it is not working;
}
}
提前谢谢..
这应该有效(没有 style.up 和 style.down 这样的东西):
function move(direction) {
var layerText = document.getElementById("newtext");
switch (direction) {
case "left":
layerText.style.left = "50px";
break;
case "right":
layerText.style.left = "150px";
break;
case "up":
layerText.style.top = "50px";
break;
case "down":
layerText.style.top = "150px";
break;
}
}
演示:http://jsfiddle.net/GE3C5/2/
layerText.style.up=50;
^
layerText.style.down=150;
^
没有属性上下。 改用顶部和底部;
default:
it is not working;
可能会导致语法错误
相关文章:
- 根据页面的位置突出显示文本中的字符
- 当选择值x时,Javascript需要在正确的位置显示文本区域,从而循环通过具有选择选项的表单
- 有人知道有没有jquery插件可以在图像上写文本,并让用户将其放置在图像内的任何位置
- jQuery/Javascript>on单击将文本放置在最后一个已知的光标位置
- 当用户单击按钮(在光标位置)时,在输入字段中添加一个文本字符串
- 如何在按键事件发生后获取文本光标的位置
- 我需要从文本框中的名字和姓氏的前两个字母到页面中的某个位置
- JavaScript 在文本区域中的特定位置插入文本
- 如何编写 JQuery 函数以在 Django 模板的特殊位置显示文本
- 链接内的内容可编辑块,如何防止重定向,但让文本选择插入符号位置更改
- 如何查找 SVG 文本位置
- 我的简单代码中的奇怪文本位置
- 尝试更改 javascript 中的文本位置
- 记录选定的文本位置,给出错误的结果
- d3.js - 基于文本宽度的文本位置
- 获取chrome中的文本位置
- 使用Javascript中的文本位置(文本跨度)将文本替换为html格式
- JavaScript选择的文本位置相对于父
- 检查溢出文本位置
- 从鼠标点击中获取输入文本位置(以字符为单位)