gpt4 book ai didi

javascript - 如何通过 PHP 将 "disabled"按钮设置回 "enabled"?

转载 作者:行者123 更新时间:2023-11-30 15:39:01 25 4
gpt4 key购买 nike

我有两个按钮,例如“保存”和“创建”。现在我的问题是当页面加载时,“创建”按钮应该“启用”并且“保存”按钮应该“禁用”。

现在,如果我单击“创建”按钮,则“保存”按钮应该“启用”,“创建”按钮现在应该“禁用”。

//php code start
<?php
$isSaveDisabled = false;
if(isset($_POST['save']))
{
echo 'Hello robin';
$isSaveDisabled = true;
}
if(isset($_POST['create']))
{
echo 'Byeeee robin';
}

?>
// php code ends
//bootstrap code start
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="BootStrap/css/bootstrap.min.css">
<title></title>
</head>
<body >
<div class="container jumbotron">

<form action="" method="post">

<div class="btn-group-xs">
<button type="submit" id="btn1" name="save" <?php if ($isSaveDisabled) { echo 'disabled="disabled"';}?>>Save</button>
<button type="submit" id="btn2" name="create">Create</button>

</div>


</form>
</div>
</body>
</html>
//bootstrap code ends

最佳答案

试一试..

//php code start
<?php
$isSaveDisabled = true;
$isCreateDisabled=false;
if(isset($_POST['save']))
{
echo 'Hello robin';
$isCreateDisabled=false;
}
if(isset($_POST['create']))
{
echo 'Byeeee robin';
$isSaveDisabled = false;
}

?>
// php code ends
//bootstrap code start
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="BootStrap/css/bootstrap.min.css">
<title></title>
</head>
<body >
<div class="container jumbotron">

<form action="" method="post">

<div class="btn-group-xs">
<button type="submit" id="btn1" name="save" <?php echo $isSaveDisabled?'disabled':''; ?>>Save</button>
<button type="submit" id="btn2" name="create" <?php echo $isCreateDisabled?'disabled':'';?>>Create</button>
</div>


</form>
</div>
</body>
</html>
//bootstrap code ends

关于javascript - 如何通过 PHP 将 "disabled"按钮设置回 "enabled"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41095524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com