我有两个按钮,例如"保存"one_answers"创建"。现在我的问题是何时加载页面,"创建"按钮应"启用",并且"保存"按钮是"禁用"的。
现在,如果我单击"创建"按钮,则应"启用"保存"按钮,现在应该"禁用"启用"按钮。
//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
可以使用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>
另外,在您中加入jQuery html。
使用A IF测试是否提交了页面与Create do disable 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>