Maison  >  Article  >  développement back-end  >  php开发之javascript第一个程序

php开发之javascript第一个程序

WBOY
WBOYoriginal
2016-08-08 09:26:161152parcourir

关于基本的概念在这里就不说了,我按照书上的代码敲出了自己的第一个javasript程序,也就是自己的hello world 。对自己是一个很大的鼓励。下面我把代码贴出来和大家一块学习。
index.php

<code><span><span><?php </span>header(<span>'Content-type:text/html'</span>);
<span>include</span><span>'test.html'</span>;


<span>?></span></span></span></code>

test.html

<code><span><span>html</span>></span><span>head</span>><span>meta</span><span>http-equiv</span>=<span>"Content-Type"</span><span>content</span>=<span>"text/html; charset=GB18030"</span>><span>script</span><span>type</span> =<span>"text/javascript"</span>><span><span><span>function</span><span>cubeme</span><span>(incomingNum)</span>{</span><span>if</span>(incomingNum ==<span>1</span>){
        <span>return</span><span>"what are you doing ?"</span>;
    }<span>else</span>{
        <span>return</span><span>Math</span>.pow(incomingNum,<span>3</span>);
    }
}

</span><span><span>script</span>></span><span>title</span>>JavaScript Test<span><span>title</span>></span><span><span>head</span>></span><span>body</span>><span>script</span><span>type</span> =<span>"text/javascript"</span>><span><span>var</span> theNum =<span>2</span>;
<span>var</span> finalNum =cubeme(theNum);
<span>if</span>(<span>isNaN</span>(finalNum)){

    alert(<span>"You should know that 1 to any power is 1."</span>);
}
<span>else</span>{
    alert(<span>"when cubed ,"</span> + theNum + <span>"is"</span> + finalNum);
}

</span><span><span>script</span>></span><span><span>body</span>></span><span><span>html</span>></span></code>

运行结果如下:

以上就介绍了php开发之javascript第一个程序,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn