HTML代码不显示输出

时间:2017-11-05 13:48:16

标签: javascript html5

我正在实施一个必须使用会话存储存储的网站。我能够存储该值并在浏览器的“存储”部分中查看它,但是当我尝试检索它时,没有任何反应。我的完整代码:

<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
</head>
<style>
.navbar 
{
overflow: hidden;
background-color: #333;
font-family: Arial;
}

.navbar a 
{
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

.dropdown 
{
float: right;
overflow: hidden;
}

.dropdown .dropbtn {
cursor: pointer;
font-size: 16px;    
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
}

.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {
background-color: #ddd;
}

.show {
display: block;
}
input[type=text]:focus {
width: 30%;
}
</style>
<body>
<form  method="POST">   
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">Shopping Cart</a>
<a href="#news">Change Details</a>
<div align="center">
<input type="text" name="searchspace" placeholder="Search">
<input type="submit" value="search" name="searchbutton" >
<p id="nametag">Hello</p>
</div>
</div>
<ul>
<li>Shampoo</li>
<li>Soap</li>
<li>Conditioner</li>
</ul>
<table align="left">
<?php
require ('sql_connect.php');
if (isset($_POST['searchbutton']))
{
if($_POST['searchspace'])
{
    $look=mysql_escape_string($_POST['searchspace']);
    $sql= mysql_query("SELECT * FROM `product_table` WHERE (name like'%$look%' or description like '%$look%')");
    if(mysql_num_rows($sql) > 0)
    {

        while ($row = mysql_fetch_array($sql)) 
     {


        echo "<tr><td>{$row['name']} by {$row['brand']}</td></tr>";

        echo "<tr><td>{$row['description']}</td></tr>";
        echo "<tr><td>{$row['price']}</td></tr>";
      echo "<tr><td><input type=submit value= 'add to cart' id={$row['product_id']}></td></tr>";
        echo "<tr><td></br></td></tr>";

      }

    }
    else
    {
        echo ("<SCRIPT LANGUAGE='JavaScript'>
            window.alert('No product Found')
            </SCRIPT>");

    }
}
}


exit();
?>
</table>
<script type="text/javascript">
document.getElementById('nametag').innerHTML = "See this works.";
</script> 
</body>
</html>

我希望这有助于您找出错误的位置。

1 个答案:

答案 0 :(得分:2)

您应该使用innerHTML代替value

&#13;
&#13;
document.getElementById('nametag').innerHTML = "See this works."; //ORIGINAL CODE: sessionStorage.getItem('user'); 
&#13;
<p id="nametag">Hello</p>
&#13;
&#13;
&#13;