我正在使用包含用户面板的网站。我想做一个你可以按下的按钮列表。当你按下一个按钮时,它会在旁边的另一个框上显示html。问题是当我按下链接到js功能的按钮时,它什么也没做。如果变量是在请求的数字处,我是否必须进行每次检查的循环?无论如何,这里是代码(其中有PHP,但它不会导致任何问题):
<!DOCTYPE html>
<html>
<head>
<title>Minecraft Server Panel v1.0</title>
<link rel="stylesheet" href="styles/styles.css" type="text/css">
<link rel="stylesheet" href="styles/inputs.css" type="text/css">
</head>
<body style="background: url('background.png'); background-repeat: no-repeat;">
<div class="page">
<div class="panel">
<div class="info" style="text-align: center;">Welcome back, <?php session_start(); echo $_SESSION['username']; ?>! <a href="php/logout.php" class="link">Logout</a></div><br />
<?php
$on = false;
if($_SESSION['loggedin'] == 1){
?>
<div class="separator"></div><br />
<div class="gray-zone" style="float: left;">
<a href="javascript: select(1);">Edit Config</a>
</div>
<div class="gray-zone overflow" style="float: right; margin-right: 100px; text-align: left;">
<script type="text/javascript">
function select(var number){
if(number == 1){ document.write('<p class="text" style="font-size: 15px;">Op permission level: </p><select class="selector" style="float: right; margin-right: 10px; margin-top: -17px;"><option value="" selected="selected">Select a level...</option> <option value="1">1</option><option value="2">2</option></select>'); }
}
</script>
</div>
<?php
} else {
header('Location: other/msgbox_disconnected.html');
}
?>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
删除函数参数中的var:
function select(number){
if(number == 1){ document.write('<p class="te….select>'); }
}
答案 1 :(得分:0)
你有没有尝试过:
<a onclick="select(1);">Edit Config</a>
答案 2 :(得分:0)
在Javascript函数中定义参数时,不需要在变量前面添加var。
正确的代码是:
function select(number){
if(number == 1){ document.write('<p class="text" style="font-size: 15px;">Op permission level: </p><select class="selector" style="float: right; margin-right: 10px; margin-top: -17px;"><option value="" selected="selected">Select a level...</option> <option value="1">1</option><option value="2">2</option></select>'); }
}
此外,您需要检查何时在PHP中使用“标头”功能。如果您尚未登录,则会收到错误消息,通知您已发送标头。在进行任何输出之前,必须确保执行任何标题更改。并且不要忘记退出或脚本将通过标题重定向运行:
header('Location: other/msgbox_disconnected.html');
exit;
答案 3 :(得分:0)
您好,您无法使用var声明JS函数,您可以将其更改为函数select(number)
我已修改了您正在运行的代码。此外,您需要在调用它之前定义JS函数
<!DOCTYPE html>
<html>
<head>
<title>Minecraft Server Panel v1.0</title>
<link rel="stylesheet" href="styles/styles.css" type="text/css">
<link rel="stylesheet" href="styles/inputs.css" type="text/css">
<script type="text/javascript">
function selectTestAlert(number)
{
if(number ==1)
{
alert("Test");
}
}
function select(number){
if(number == 1)
{
document.write('<p class="text" style="font-size: 15px;">Op permission level: </p><select class="selector" style="float: right; margin-right: 10px; margin-top: -17px;"><option value="" selected="selected">Select a level...</option> <option value="1">1</option><option value="2">2</option></select>');
}
}
</script>
</head>
<body style="background: url('background.png'); background-repeat: no-repeat;">
<div class="page">
<div class="panel">
<div class="info" style="text-align: center;">Welcome back, <?php session_start(); echo $_SESSION['username']; ?>! <a href="php/logout.php" class="link">Logout</a></div><br />
<?php
$on = false;
if($_SESSION['loggedin'] == 1){
?>
<div class="separator"></div><br />
<div class="gray-zone" style="float: left;">
<a href="javascript: select(1);">Edit Config</a>
</div>
<div class="gray-zone overflow" style="float: right; margin-right: 100px; text-align: left;">
function select(number){
if(number == 1){ document.write('<p class="text" style="font-size: 15px;">Op permission level: </p><select class="selector" style="float: right; margin-right: 10px; margin-top: -17px;"><option value="" selected="selected">Select a level...</option> <option value="1">1</option><option value="2">2</option></select>'); }
}
</div>
<?php
} else {
header('Location: other/msgbox_disconnected.html');
}
?>
</div>
</div>
</body>
</html>