如何将 "disabled" 按钮设置回 "enabled" 至 PHP?
How to set the "disabled" button back to "enabled" thru PHP?
我有两个按钮,例如 "Save" 和 "Create"。现在我的问题是当页面加载时,"Create" 按钮应该 "enabled" 而 "Save" 按钮应该是 "disabled".
现在,如果我单击 "Create" 按钮,那么 "Save" 按钮应该是 "enabled","Create" 按钮现在应该是 "disabled"。
//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
可以使用 jQuery 来完成。
试试这个:
$(document).on('click','#btn2',function(){
$(this).prop('disabled',true);
$('#btn1').prop('disabled',false);
});
将此添加到您的 HTML
<script>
$(document).on('click','#btn2',function(){
$("#btn2").prop('disabled',true);
$("#btn1").prop('disabled',false);
});
</script>
此外,在你 html 中包含 jQuery。
使用 if 测试页面是否使用 create 提交以禁用创建
<div class="btn-group-xs">
<?php $create,$save = ''; if(isset($_POST['create'])) {$create = 'disabled';} else {$save = 'disabled';}?>
<button type="submit" id="btn1" name="save" <?php $save?>>Save</button>
<button type="submit" id="btn2" value="create" name="create" <?php $save?> >Create</button>
</div>
试试吧..
//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
我有两个按钮,例如 "Save" 和 "Create"。现在我的问题是当页面加载时,"Create" 按钮应该 "enabled" 而 "Save" 按钮应该是 "disabled".
现在,如果我单击 "Create" 按钮,那么 "Save" 按钮应该是 "enabled","Create" 按钮现在应该是 "disabled"。
//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
可以使用 jQuery 来完成。
试试这个:
$(document).on('click','#btn2',function(){
$(this).prop('disabled',true);
$('#btn1').prop('disabled',false);
});
将此添加到您的 HTML
<script>
$(document).on('click','#btn2',function(){
$("#btn2").prop('disabled',true);
$("#btn1").prop('disabled',false);
});
</script>
此外,在你 html 中包含 jQuery。
使用 if 测试页面是否使用 create 提交以禁用创建
<div class="btn-group-xs">
<?php $create,$save = ''; if(isset($_POST['create'])) {$create = 'disabled';} else {$save = 'disabled';}?>
<button type="submit" id="btn1" name="save" <?php $save?>>Save</button>
<button type="submit" id="btn2" value="create" name="create" <?php $save?> >Create</button>
</div>
试试吧..
//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