【发布时间】:2016-11-24 16:54:26
【问题描述】:
我一直在尝试用两个按钮为我的网络服务器创建一个简单的 menu.php
b1=登录,b2=注册。它们中的每一个都将调用其单独的函数,然后扫描 id='main' 块并将其内部 html 更改为类似于<?php include('testLogIN.php') ?> 和<?php include('testRegister.php') ?> 的内容。这些按钮会擦除 id='main' 的块的内部 html,但在我的服务器上,单击时按钮什么也不做。我被引导相信这可能是嵌套字符串如何工作的问题,因此echo "He said 'haha' and left." 不会正确打印He said 'haha' and left.。我知道我的描述可能到处都是,但请多多包涵。
@charset "UTF-8";
.right{
margin:1%;
position:relative;
clear:right;
float:right;
right:15px;
}
.left{
margin:1%;
position:relative;
clear:left;
float:left;
left:10px;
}
.bleft{
margin:1%;
position:relative;
float:left;
width=15px;
}
.fleft{
float:left;
}
.mainbox{
margin:2%;
width:450px;
height:auto;
}
.box{
clear:left;
float:left;
margin:1%;
width:280px;
height:33px;
}
img{
max-width: 100%;
max-height: 100%;
width: auto;
}
.stat{
float:right;
position:fixed;
right:10px;
}
.bolded{
border-width: 5px;
size:5px;
}
h2{
margin-left:2px;
}
.white{
color:#DDD;
}
.black{
background-color:#333;
}
hr{
clear:left;
}
<!DOCTYPE html>
<html>
<head>
<title>Main</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
.abs{
position: absolute;
top: 0;
left: 0;
}
.rel{
position: relative;
}
a:visited{
color: green;
}
body{
margin: 0;
padding: 0;
border: 0;
background--image: url("images/dragon.jpg");
background-size: cover;
}
</style>
</head>
<body>
<div class="rel">
<img src="images/dragon.jpg">
<div id='main' class="mainbox black abs">
<button onclick='tologin()'>Log in</button>
<button onclick='toregister()'>Register</button>
</div>
</div>
</body>
</html>
<script>
function tologin(){
document.getElementById("main").innerHTML ="<?php include('unistuff/LogIN/login.php');?>";
}
function toregister(){
document.getElementById("main").innerHTML ="<?php include('unistuff/LogIN/toregister.php');?>";
}
</script>
【问题讨论】:
-
PHP 代码只能在服务器上执行。更改
innerHTML只会更改 HTML(客户端事件)。单击“登录”后,您可能需要向服务器发送请求,服务器将为您生成一个新页面。
标签: javascript php html include