如何用JAVASCRIPT脚本修改网页的内容? 能不能给个例子,就假如一个网页上有3个DIV,现在要改变其中一个DIV的值,一个DIV的位置,能够给个例子 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请看代码eg:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title> New Document </title><meta name="Generator" content="EditPlus"><meta name="Author" content=""><meta name="Keywords" content=""><meta name="Description" content=""></head><body><form method=post action=""><DIV ALIGN="left" id="div1"style="width:100;height:200;background-color=red;">dd</DIV><input type="button" value="change" onclick="getObjectById('div1').innerText='hello world!';getObjectById('div1').style.backgroundColor='gray';"></form><script language="JavaScript"><!--function getObjectById(id){ if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!')); if (document.all) return document.all(id); try {return document.getElementById(id);} catch(e){ return eval(id);}}//--></script></body></html> <div id="division1"></div><div id="division2"></div><div id="division3"></div><input type="text" onkeyup="document.getElementById('division2').innerHTML = this.value;"><input type="button" onclick="divmove();" value="move div"><script language="javascript">function divmove(){ var t = 100; var l = 300; document.getElementById('division2').style.position = 'absolute'; document.getElementById('division2').style.top = t; document.getElementById('division2').style.left = l;}</script> 先打开一个网页,然后在地址栏中输入以下代码,然后回车就行了。javascript:document.body.contentEditable='true';document.designMode='on';void(0); 谢谢各位的回答,我是想这样,在一个页面上有很多个DIV,我用鼠标点击,点中一个DIV,就弹出一个编辑框,然后输入修改值,然后再修改页面的内容.还有就是用鼠标控制DIV的移动. 还有就是<!--function getObjectById(id){ if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!')); if (document.all) return document.all(id); try {return document.getElementById(id);} catch(e){ return eval(id);}}//-->其中<!--和//-->是什么意思,加和不加有什么区别了? “<!—”和标识符”—>”之间是可以在一些不支持JAVASCIRPT的浏览器里隐藏JAVASCRIPT。在“//”后的是可被忽略的注释。这里要注意的是:使用上述两种注释都必须在同一行内完成,如要另外提行写注释,应另外在相应的行加上这两种标识符的一种,不然,系统会提示出错信息。 用div.innerHtml来修改就可以了。 为什么有时候 div.innerHtml 是空的了? 关于js日期函数 用sublime text2 编写JS 为什么会出现乱码啊? 用弹出窗口实现一个功能? JS函数的参数传递问题 这个时间数字是怎么得来的,用js能得到吗? 如何在html文件中显示本地的flash文件 JS动态操作,会的帮助一下,不知道的捧捧人场 还有比这简单的问题???~!~ 怎么用正则表达式判断一个字符串只含有x和o,长度为5 这段程序怎么修改啊~ 如何处理document.write("<script>.....<\/script>")这样的语句 js里面定义一个数组 怎样把数组里面的值动态的添加到一个下拉框中?
eg:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head><body>
<form method=post action="">
<DIV ALIGN="left" id="div1"style="width:100;height:200;background-color=red;">dd</DIV>
<input type="button" value="change" onclick="getObjectById('div1').innerText='hello world!';
getObjectById('div1').style.backgroundColor='gray';">
</form>
<script language="JavaScript">
<!--
function getObjectById(id)
{
if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!'));
if (document.all) return document.all(id);
try {return document.getElementById(id);} catch(e){ return eval(id);}
}
//-->
</script>
</body>
</html>
<div id="division2"></div>
<div id="division3"></div>
<input type="text" onkeyup="document.getElementById('division2').innerHTML = this.value;">
<input type="button" onclick="divmove();" value="move div">
<script language="javascript">
function divmove()
{
var t = 100;
var l = 300; document.getElementById('division2').style.position = 'absolute';
document.getElementById('division2').style.top = t;
document.getElementById('division2').style.left = l;
}
</script>
javascript:document.body.contentEditable='true';document.designMode='on';void(0);
还有就是
<!--
function getObjectById(id)
{
if (typeof(id) != "string" || id == "") throw(new Error(-1, '传到函数 getObjectById 里的参数不对!'));
if (document.all) return document.all(id);
try {return document.getElementById(id);} catch(e){ return eval(id);}
}
//-->
其中<!--和//-->是什么意思,加和不加有什么区别了?
这里要注意的是:使用上述两种注释都必须在同一行内完成,如要另外提行写注释,应另外在相应的行加上这两种标识符的一种,不然,系统会提示出错信息。