getElementById innerHTML未定义

时间:2015-10-14 19:07:35

标签: javascript html innerhtml getelementbyid

<div class>item2位于同一world时,item1会返回undefined,但function Delivered(xCode, tNo) { document.getElementById("item1").innerHTML = "hello"; document.getElementById("item2").innerHTML = "world"; } 会返回<span id="item2"></span>

item1

但是,如果我只删除hello<div id="details"> <div class="right" id="rightDIV">content...<span id="item1"></span>..inserted here</p> <p> more content...<span id="item2"></span> </div> </div> 再次报告item2

<div class>

我尝试将<div id="details"> <div class="left" id="leftDIV">item: <b><span id="item3"></span></b> <p>via <b>airmail;</b></p> </div> <div class="right" id="rightDIV">Status: <b>active</b> <p>item with reference <span id="item1"></span> content here <span id="item2"></span></p> <p>Thank you&trade;</p> </div> </div> 放入新#details { height:200px; width:600px; font-family: Tahoma; color: #000; margin: 0px; font-size: 12px; } #details .left{ width:33%; height:200px; padding: 15px; background-color: #fff; float: left; overflow:hidden; visibility: hidden; } #details .right{ width:40%; height:200px; padding: 15px; background-color: #ccc; float: left; overflow:hidden; visibility: hidden; } function Delivered(xCode, tCode) { document.getElementById("leftDIV").style.visibility = "visible"; document.getElementById("rightDIV").style.visibility = "visible"; document.getElementById("item3").innerHTML = tCode; document.getElementById("item1").innerHTML = tCode; document.getElementById("item2").innerHTML = xCode; } 但仍未成功。我做错了什么?

编辑:我可以发布原始代码吗?对不起,先发帖。

2015-10-14 14:55:35.438-0400 INFO  No SSL certificate found, generating a self-signed certificate..
14:55:35.936 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework
14:55:36.105 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
14:55:36.106 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
14:55:36.107 [main] DEBUG i.n.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
14:55:36.107 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: true
14:55:36.108 [main] DEBUG i.n.util.internal.PlatformDependent - Java version: 7
14:55:36.108 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noUnsafe: false
14:55:36.109 [main] DEBUG i.n.util.internal.PlatformDependent - sun.misc.Unsafe: available
14:55:36.109 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noJavassist: false
14:55:36.110 [main] DEBUG i.n.util.internal.PlatformDependent - Javassist: unavailable
14:55:36.110 [main] DEBUG i.n.util.internal.PlatformDependent - You don't have Javassist in your class path or you don't have enough permission to load dynamically generated classes.  Please check the configuration for better performance.
14:55:36.110 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.tmpdir: /tmp (java.io.tmpdir)
14:55:36.110 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
14:55:36.110 [main] DEBUG i.n.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false
14:55:36.119 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetectionLevel: simple
14:55:36.135 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: unpooled
14:55:36.135 [main] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 65536
2015-10-14 14:55:41.341-0400 INFO  Successfully started database
2015-10-14 14:55:41.405-0400 INFO  Starting HTTP on port 7474 (32 threads available)
2015-10-14 14:55:41.659-0400 INFO  Successfully shutdown Neo4j Server
2015-10-14 14:55:42.224-0400 INFO  Successfully stopped database
2015-10-14 14:55:42.227-0400 ERROR Failed to start Neo4j: Starting Neo4j failed: tried to access field org.neo4j.server.rest.repr.RepresentationFormat.mediaType from class org.neo4j.server.rest.repr.RepresentationFormatRepository Starting Neo4j failed: tried to access field org.neo4j.server.rest.repr.RepresentationFormat.mediaType from class org.neo4j.server.rest.repr.RepresentationFormatRepository
org.neo4j.server.ServerStartupException: Starting Neo4j failed: tried to access field org.neo4j.server.rest.repr.RepresentationFormat.mediaType from class org.neo4j.server.rest.repr.RepresentationFormatRepository
        at org.neo4j.server.exception.ServerStartupErrors.translateToServerStartupError(ServerStartupErrors.java:67)
        at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:234)
        at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:96)
        at org.neo4j.server.CommunityBootstrapper.start(CommunityBootstrapper.java:48)
        at org.neo4j.server.CommunityBootstrapper.main(CommunityBootstrapper.java:35)
Caused by: java.lang.IllegalAccessError: tried to access field org.neo4j.server.rest.repr.RepresentationFormat.mediaType from class org.neo4j.server.rest.repr.RepresentationFormatRepository
        at org.neo4j.server.rest.repr.RepresentationFormatRepository.<init>(RepresentationFormatRepository.java:46)
        at org.neo4j.server.AbstractNeoServer.createDefaultInjectables(AbstractNeoServer.java:641)
        at org.neo4j.server.AbstractNeoServer.configureWebServer(AbstractNeoServer.java:360)
        at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:216)
        ... 3 more

这是我的剧本:

$.getScript( "externalfile.js" )
    .done(function( script, textStatus ) {
        d.init();
    })
});

我不确定要粘贴多少代码,因为我不确定它们是否相关:)

1 个答案:

答案 0 :(得分:0)

您在编写js代码后忘记调用该函数。

function Delivered(xCode, tNo) {
    document.getElementById("item1").innerHTML = "hello";
    document.getElementById("item2").innerHTML = "world";
} 

Delivered();

在html中你已经关闭了p元素,但你从未打开过一个

 <div id="details"> 
   <div class="right" id="rightDIV">
    content...<span id="item1"> </span>..inserted here</p> -----> Here
    you opened but never closed <--------- <p>more content...<span id="item2"></span>
    </div>
</div>

在Js

中这样做
function delivered(xCode, tNo) {
    document.getElementById("item1").innerHTML = "hello";
    document.getElementById("item2").innerHTML = "world";
}

delivered();

和html一样

<div id="details"> 
   <div class="right" id="rightDIV"><p>content...<span id="item1"></span>..inserted here</p>
       <p> more content...<span id="item2"></span></p>
   </div>
</div>