页面是一个表单,在头文件中有大约6个按钮,它们决定了你是一个页面,如果我们在第一页(第一个按钮),我想要禁用除第一个按钮以外的所有按钮
谢谢
这是在foreach循环中用不同的页面名称填充所有按钮:
echo '<input type="submit" name="submit" id="completeButton" class="menu' . ($page == $p ? '_selected':'') . '" value="' . $p . '">';
答案 0 :(得分:4)
我猜你在某个地方有一个页面ID
您是否通过按钮循环创建它们?
如果你不循环使用它们,你只需要添加类似
的内容<input type="button" <?php if ($pageId !== 1) echo 'disabled="disabled"' ?> />
然后对于第二个按钮,用$ pageId!== 2测试它,依此类推......
答案 1 :(得分:1)
试试这个
<html>
<button type="button">bttn1</button>
<button type="button" disabled="disabled">bttn2</button>
<button type="button" disabled="disabled">bttn3</button>
<button type="button" disabled="disabled">bttn4</button>
<button type="button" disabled="disabled">bttn5</button>
<button type="button" disabled="disabled">bttn6</button>
</html>
答案 2 :(得分:0)
你可以通过多种方式实现这一目标,但6个按钮似乎让我感到困惑和不必要。
为什么不创建一个标有“下一步”的按钮?
答案 3 :(得分:0)
我建议使用会话来跟踪用户的位置。您可以通过检查会话变量来轻松检查:
<?php
/**
* Checks to see if a session key exists and returns the
* corresponding value otherwise returns false
*
* @param <String> $key
* @return <String/Boolean>
*/
function session($key) {
if(isset($_SESSION[$key])) {
return $_SESSION[$key];
}
return false;
}
if(!session('curr_page')) {
// redirect to first page and set the curr page to one
$_SESSION['curr_page'] = 1;
header('Location: path/to/your/page.php');
}
$curr_page = session('curr_page');
// now you can use a series of if statements to disable
// the other buttons
?>
<?php if($curr_page > 0): ?>
// display first button etc
<?php endif; ?>
<?php if($curr_page > 1): ?>
// display second button etc
<?php endif; ?>
<?php if($curr_page > 1): ?>
// display second button etc
<?php endif; ?>
我希望这会有所帮助。