2016-12-12 17 views
0

こんにちは、私のコードに問題があります このコードでは、保存ボタンを押してから「Hello PHP」の印刷とラベルの色を変更しますが、私がボタンタイプで提出すると 'Hello PHP'とラベルの色が変わらず、ボタンタイプでボタンを押した後にラベルの色が変わるが、 'hello PHP'は表示されません。このコードからはみ出した送信ボタンでJavaScriptのラベルの色を変更する方法

にこれは私のコードです:

<?php 
//php code 
$isSaveDisabled=true; 
$isCreateDisabled=false; 

if(isset($_POST['save_button'])) 
{ 
echo 'Hello PHP'; 
} 

if(isset($_POST['create_button'])) 
{ 
$isSaveDisabled=false; 
} 
?> 
// BootStrap Code 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>My New PHP CODE</title> 

<link rel="stylesheet" href="bootStrap/css/bootstrap.css"/> 
<link rel="stylesheet" href="bootStrap/css/bootstrap.min.css"/> 

<script type="text/javascript"> 
function myFunction() { 
document.getElementById("myID").style.color = "#ff0000"; 
} 
</script> 

</head> 
<body> 
<div class="container jumbotron text-center"> 

    <form action="" method="POST" class="form-inline"> 
     <div class="form-group"> 
      <label for="fname" id="myID">FIRST NAME</label> 
      <input type="text" name="fname" class="form-control" > 
      <label for="nlame">LAST NAME</label> 
      <input type="text" name="lname" class="form-control" > 
     </div> 
     <br><br> 
      <div class="btn-group"> 
      <button type="submit" name="save_button" onclick="myFunction();" <?php echo $isSaveDisabled? 'disabled':'';?>>SAVE</button> 
      <button type="submit" name="create_button" <?php echo $isCreateDisabled? 'disabled':''?> >CREATE</button> 

     </div> 
    </form> 
</div> 
</body> 
</html> 

答えて

1

ラベルは、提出にckick後の色を変更しますが、ページがREFRですすぐにエスジング。

<?php 

if($isSaveDisabled) { 
    echo '<script>document.getElementById("myID").style.color = "#ff0000";</script>' 
} 
?> 

ので、あなたのコードが表示されます::あなたはボタン「保存」をクリックしてかどうかをチェックすることにより、ラベルに色をすることができます

<?php 
//php code 
$isSaveDisabled=true; 
$isCreateDisabled=false; 

if(isset($_POST['save_button'])) 
{ 
echo 'Hello PHP'; 
} 

if(isset($_POST['create_button'])) 
{ 
$isSaveDisabled=false; 
} 
?> 
// BootStrap Code 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>My New PHP CODE</title> 

<link rel="stylesheet" href="bootStrap/css/bootstrap.css"/> 
<link rel="stylesheet" href="bootStrap/css/bootstrap.min.css"/> 

<script type="text/javascript"> 
function myFunction() { 
document.getElementById("myID").style.color = "#ff0000"; 
} 
</script> 

</head> 
<body> 
<div class="container jumbotron text-center"> 

    <form action="" method="POST" class="form-inline"> 
     <div class="form-group"> 
      <label for="fname" id="myID">FIRST NAME</label> 
      <input type="text" name="fname" class="form-control" > 
      <label for="nlame">LAST NAME</label> 
      <input type="text" name="lname" class="form-control" > 
     </div> 
     <br><br> 
      <div class="btn-group"> 
      <button type="submit" name="save_button" onclick="myFunction();" <?php echo $isSaveDisabled? 'disabled':'';?>>SAVE</button> 
      <button type="submit" name="create_button" <?php echo $isCreateDisabled? 'disabled':''?> >CREATE</button> 

     </div> 
    </form> 
</div> 

<?php 
    if($isSaveDisabled) { 
    echo '<script>document.getElementById("myID").style.color = "#ff0000";</script>'; 
    } 
?> 
</body> 
</html> 
+0

をあなたにそれは本当に私のために非常に有用ですので、多くの兄弟をありがとうございます。 – user3526020

関連する問題