如何将Javascript变量插入到p标签中

时间:2015-07-15 13:33:14

标签: javascript html variables

基本上我有变量叫test,我试图把它插入到html标签中。我试过在p标签中添加一个id,然后使用

调用它
var test1 = DynamicContent.simpleTest_Sheet1[0].Ad_Copy_1 = "Invest in an<br/>International Career";
    document.getElementById("test").innerHTML = test1; 

然而,这似乎不起作用,因为文本在运行时不会显示。我究竟做错了什么?完整代码如下:

<html>
<head>
<meta charset="utf-8">
<title>animatebanner</title>
<link rel="stylesheet" href="css/animate.css" type="text/css">
<link rel="stylesheet" href="css/styles.css" type="text/css">

<style type="text/css">
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
</style>
<meta name="ad.size" content="width=300,height=600">

<script type="text/javascript">
var clickTag = "http://www.google.com"; </script>
<!--
 * Dynamic Content Enable code for Profile: 1051982
 *
 * The following code initializes the following dynamic variables for
 * development testing and live serving of Fields associated to the above profile
-->

<!-- DynamicContent Start: HTML5 invocation code. -->
<script type="text/javascript">

// Dynamic Content variables and sample values
    Enabler.setProfileId(1051982);
    var devDynamicContent = {};

    devDynamicContent.simpleTest_Sheet1= [{}];
    devDynamicContent.simpleTest_Sheet1[0]._id = 0;
    devDynamicContent.simpleTest_Sheet1[0].Unique_ID = 1;
    devDynamicContent.simpleTest_Sheet1[0].Reporting_Label = "londoncoursedynamiccontent";
    devDynamicContent.simpleTest_Sheet1[0].LI_ID = 3059723;
    devDynamicContent.simpleTest_Sheet1[0].Background_Colour = "#2d2d2d";
    devDynamicContent.simpleTest_Sheet1[0].Logo = {};
    devDynamicContent.simpleTest_Sheet1[0].Logo.Type = "file";
    devDynamicContent.simpleTest_Sheet1[0].Logo.Url = "https://s0.2mdn.net/ads/richmedia/studio/pv2/37301334/dirty/no_timer/images/logo.png";
    devDynamicContent.simpleTest_Sheet1[0].Font_Colour_1 = "#FFFFFF";
    devDynamicContent.simpleTest_Sheet1[0].Ad_Copy_1 = "Invest in an<br/>International Career";
    devDynamicContent.simpleTest_Sheet1[0].Ad_Copy_2 = "Find out more";
    devDynamicContent.simpleTest_Sheet1[0].Exit_URL = "www.google.com";
    devDynamicContent.simpleTest_Sheet1[0].Default = false;
    devDynamicContent.simpleTest_Sheet1[0].Active = true;
    Enabler.setDevDynamicContent(devDynamicContent);

    var test1 = DynamicContent.simpleTest_Sheet1[0].Ad_Copy_1 = "Invest in an<br/>International Career";
    document.getElementById("test").innerHTML = test1; 
</script>

<!--
 * You may access the variables in the following manner
 * AFTER the Studio Enabler is initialized.
 * var Unique_ID = dynamicContent.simpleTest_Sheet1[0].Unique_ID;
 * Note: be sure to use "dynamicContent", not "devDynamicContent"
-->
</head>

<body>

<a href="javascript:window.open(window.clickTag)" style="color:#000000">

<div style="width:300px; height:600px; z-index:1; background-color:#2d2d2d; position:fixed; margin:0px;" class="click-layer" id="clickLayer">

<p style="margin-left:27px; margin-top:20px; position:fixed; text-align:center; font-size:26px; font-family: 'Open Sans', sans-serif; line-height:1.1; color:#FFFFFF;" class="animated fadeInDown text1" id="test"></p>

<img src="images/pic1.jpg" width="298" height="300" alt="" style="margin-top:100px;" class="animated fadeIn pic1"/> 

<input type="button" style="border:0px; position:fixed; margin-top:105px" class="animated fadeIn calltoaction btn">

<p style="margin-left:80px; margin-top:112px; position:fixed; text-align:center; font-size:20px; font-family: 'Open Sans', sans-serif; line-height:1; z-index:1; color:#FFFFFF;" class="animated infinite fadeInCustom text3"><b>Find out more</b></p>
<img src="images/logo.png" width="116" height="22" alt="" style=" margin-left:100px; margin-top:160px" class="animated fadeInUp logo"/> </div></a>
</body>
</html>

0 个答案:

没有答案