0

我想更改 div 的内容,使用 javascript 和innerHTML.

我无法让它工作。我刚刚添加了更改 div 的代码,在此之前代码工作正常。我仔细检查了语法。

我正在使用 webshims、openlayers 和 jquery/javascript

在控制台中我看到

Uncaught TypeError: Cannot set property 'innerHTML' of null imagegaledit - myFile.php :768 so.onmessage - myFile.php :324

768是那条线 document.getElementById("imgedtitle").innerHTML=mnmi[0];

324是这个 imagegaledit(0);

一点帮助?谢谢

编辑 websockets 工作和响应正常

这是代码(简明扼要)

    <!doctype html>

    <header>    
    <meta charset="utf-8">
    <meta http-equiv="content-type" content="text/html">

    <script src="jquery-1.8.2.min.js"></script> 
    <script src="js-webshim/minified/extras/modernizr-custom.js"></script>  
    <script src="js-webshim/minified/polyfiller.js"></script>
    <script>    
        $.webshims.polyfill();  
    </script>

    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>

    <!--open layers api library-->
    <script type='text/javascript' src='OpenLayers.js'></script>
    <script type='text/javascript'>

    //openlayers vars and stuff here...

    function init(){

       //when a point on map clicked...
       function selected_feature(event){
             //some openlayers magic...
              var so = new WebSocket("ws://localhost:8000");         

              so.onerror=function (evt) 
               {response.textContent = evt;}

                so.onopen = function(){
                response.textContent = "opened";
                so.send(JSON.stringify({command:'map',fmid:jas}));
                 }


                so.onmessage = function (evt) {    
                  var received_msg = evt.data;
                  var packet = JSON.parse(received_msg); 
                  //pass data to var and arrays...                       
                 imagegaledit(0);
                }
          }//closes function selected_feature

    }//closes init

    function imagegaledit (w){
        if (w==0){
           document.getElementById("imgedtitle").innerHTML=mnmi[0];
          }
    }//closes imagegaledit 


</script>    

    <body onload='init();'>
        Title</br><div id="imgedtitle"> </div> </br>
    </body>
4

1 回答 1

0

您需要一个结束脚本标记:

</script> 
<body>
于 2013-09-29T01:59:53.200 回答