将HTML编码为JavaScript代码

时间:2015-07-25 20:05:19

标签: javascript html

我需要在JavaScript中编写一些HTML代码

HTML:

<!--start ramadan-->
<section id="ramadan" style="min-width:1200px">
   <div class="container">
   <div class="baner">
      <div class="page">
         <div class="slider">
            <div class="slider-wrapper theme-default">
               <div id="slider" class="nivoSlider">
                  <img src="royamotion2015/img/img/001.jpg"   title=""/>
                  <img src="royamotion2015/img/img/002.jpg"  alt="" title="" />
                  <img src="royamotion2015/img/img/003.jpg"  alt="" data=""-transition="slideInLeft" />
                  <img src="royamotion2015/img/img/004.jpg"  alt="" title="#htmlcaption" data=""-transition="slideInRight" />
               </div>
               <div id="htmlcaption" class="nivo-html-caption">
                  <strong></strong> <em> the code in view-source this page </em>  
                  <a href="#"></a>.
               </div>
            </div>
         </div>
      </div>
   </div>
</section>
<!--end ramadan-->

如何编写像这样的JavaScript代码?

http://jj.org.sa/aa/1.html

1 个答案:

答案 0 :(得分:1)

我想你问的是如何将这段代码放在HTML中......?

如果是这样,那很简单。将<script>标记放入html:

<script>
    function url() { 
        var x = window.location.pathname; 
        if  (x=="/index/index.php") { 

        } 
    }
</script>

您的JavaScript代码将有效。

如果你说你需要用JavaScript编写整个页面,这在我的大脑中是疯狂的,那么你必须使用document.write();并编写每行代码:

<script>
    document.write("<section id=\"ramadan\" style=\"min-width:1200px\">");
    document.write("<div class=\"container\">");
    etc. etc.
</script>