Javascript不会更改文档? [英] Javascript doesn't change document?

查看:33
本文介绍了Javascript不会更改文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看一下下面的示例代码,它不起作用:

Take a look at this example code, which doesn't work:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script type="text/javascript">
<!--

function moveMe() {
        document.getElementById('moveme').top = 200;
        document.getElementById('moveme').style.backgroundcolor = 'green';
        document.getElementById('writeme').innerHtml = 'abc';
        alert('called!');
}


// -->
</script>


<style type="text/css">

.moveable {
    position: absolute;
    top: 30px;
    left: 200px;
    width: 100px;
    height: 100px;
    background-color: yellow;
}

#writeme {
    background-color: red;
    color: white;
}

</style>


</head>

<body>

<div id="moveme" class="moveable" onClick="moveMe()">
<p id="writeme">Hello!</p>
</div> 

</body>

</html>

当我单击文本时,将显示警报,但是文档中没有任何更改.段落文本不会被覆盖,div不会移动...在FF和IE中对其进行了测试,还通过Firebug检查了DOM:奇怪的是,新值已写入节点,但它们以粗体显示,并且旧的价值观仍然存在.WTF?

When I click on the text the alert is displayed, but nothing is changed in the document. The paragraph text is not overwritten, the div is not moved... tested it in FF and IE, also checked the DOM via Firebug: strange thing is that the new values are written to the nodes, but they are displayed in bold, and the old values are still there. WTF?

我想我这里缺少一些基本知识.

I guess I'm missing something fundamental here.

推荐答案

  • 非零长度要求单位,"200"缺少其单位
  • JavaScript区分大小写: backgroundColor innerHTML
  • 由于您似乎正在使用XHTML,因此您的脚本是已注释掉
  • 这篇关于Javascript不会更改文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆