试图:按钮调用函数将id替换为html,进入<! - ?php include(“”)? - >

时间:2016-11-24 16:54:26

标签: javascript php html include

我一直在尝试使用两个按钮为我的Web服务器创建一个简单的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>

1 个答案:

答案 0 :(得分:0)

由于php忽略脚本(它将包含两个文件而不会屈服于javascript),我建议你研究Loading file with javascript

或者你可以使用jQuery加载方法(不加载PHP文件):

<script>
    function tologin(){
        $("#main").load('login.html');
    }
    function toregister(){
        $("#main").load('register.html');
    }
</script>

如果必须是PHP,那么你可以使用Ajax