Software Archive
Read-only legacy content
17061 ディスカッション

<body> tag disappear automatically!

Ram_Pawar
ビギナー
863件の閲覧回数

Hello friends, 

I'm making one small app, in which I created a function to show current time of device, calling it on body load, and using it in div. But problem is that once I open design (after writing code), <body onload="startTime()"> disappears, and time doesn't work, And if I go directly from code to emulator, time works perfectly. 
 

Here is code of function: 

function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('horas_atuais').innerHTML = h+":"+m+":"+s;
    var t = setTimeout(function(){startTime()},500);
}

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}

I'm starting this function when body loads :

<body onload="startTime()">

And showing it in div: 

<div class="container" style="width: 100%; position: relative; height: auto; text-align: right;"
            data-appbuilder-object="container">
            
            <div id="horas_atuais" class="text_item" data-appbuilder-object="text">Horas </div>

</div>

Thanks! ~(^_^)~

0 件の賞賛
4 返答(返信)
Elroy_A_Intel
従業員
863件の閲覧回数

When using the Intel XDK App Designer (Design) tool, any manual edits to the source Code will be overwritten in the index.html by the tool. If you go to the Design panel from the Code panel then add a UI element, the code is regenerated removing all of the manual edits.

Ram_Pawar
ビギナー
863件の閲覧回数

And isn't there any way to fix the manual code? 
Thanks! 

Elroy_A_Intel
従業員
863件の閲覧回数

At this moment, there isn't any solutions to address this issue.

PaulF_IntelCorp
従業員
863件の閲覧回数

Instead of inserting JavaScript into the html file, put it in a separate JS file and add an ID to the tag of interest. Then, in your JS code, use something like this to add your event handler:

var el ;

el = document.getElementById("id_startTime") ;
el.addEventListener("load", startTime, false) ;

 

返信