我在html doc的标题中有以下相关代码:
test1.value = System.Gadget.Settings.read("Date1");
我正在尝试在html doc的正文中显示test1值。
我使用时显示:
<input type="text" id="test1" />
但是当我使用(在体内)时不起作用:
<script type="text/javascript">
document.write(document.getElementById('test1').id);
</script>
任何建议都将不胜感激
答案 0 :(得分:7)
这可能很明显,但为什么不写:
<html>
<body>
<div>Here's the Date1 value:
<script type="text/javascript">
document.write(System.Gadget.Settings.read("Date1"));
</script>
</div>
</body>
</html>
如果这不符合您的要求,请说明您的预期输出。
答案 1 :(得分:0)
这不起作用,因为你的脚本在页面的标题中,而输入text1的声明在主体中。所以发生的事情是,当浏览器运行脚本时,它将找不到对象。
你需要这样的东西......
<html>
<body>
<input type="text" id="test1" />
<script type="text/javascript">
document.write(document.getElementById('test1').id);
</script>
</body>
</html>