2016-09-06 2 views
0

나는 좋은 찾고 CSS 스타일 오프 버튼에 다음 코드를사용자가 확인란을 선택하면 PHP 코드를 제출

<?php 
$wifi2g=file_get_contents("wifi2g.txt"); 
$wifi2g= trim ($wifi2g); 
?> 

<link rel="stylesheet" type="text/css" href="style.css"> 
<div class="onoffswitch"> 
    <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" <?php if ($wifi2g == "enabled") {echo "checked";} ?>> 
    <label class="onoffswitch-label" for="myonoffswitch"> 
     <span class="onoffswitch-inner"></span> 
     <span class="onoffswitch-switch"></span> 
    </label> 
</div> 

난 당신이 wifi2g.txt에서 보는 바와 같이 읽고에있는 버튼의 위치를 ​​정의 할 수 있습니다 또는 꺼짐 (선택 또는 선택 취소). ftp server wifion.php와 wifioff.php에 업로드하고 싶은 두 개의 스크립트가 있습니다. 이 스크립트는 버튼 위치에 따라 다릅니다. 사용자가 버튼 위치를 ON (또는 선택)으로 설정하면 wifion.php를 업로드하고 wifioff.php를 업로드하려면 선택을 해제하거나 선택 취소합니다. 이 작품을 어떻게 만들 수 있습니까? 난 당신이 jQuery를 잘 알고있는 경우 여기에이 버튼을 https://proto.io/freebies/onoff/

+0

계속하려는 경우 사용해야하는 발견 자바 스크립트. – Barmar

답변

0

, 당신이

$('.onoffswitch-checkbox').on('change',function(){ 
    var input = $(this); 

    if(input.prop('checked') == true){ 
     input.closest('form').submit(); 
    } 
}); 

을 할 수 또는 같은 페이지를 사용 아약스

$('.onoffswitch-checkbox').on('change',function(){ 
    var input = $(this); 

    if(input.prop('checked') == true){ 
     $.ajax({ 
       url:'test.php' 
       ,type:'POST' 
       ,data: {btn:'was checked!'} 
     }).done(function(data){ 
      // do something with returning of php 
     }); 
    } 
}); 
+0

질문은 체크 박스의 상태에 따라'wifion.php' 또는'wifioff.php'에 제출하는 것을 말합니다. 그것은 당신의 코드에서 어디에 있습니까? [ – Barmar

+0

그것은 또 다른 파일 wifion.php입니다. 이 경우 버튼 변경 example.button을 on으로 설정하면 php 스크립트는 ftp로 파일을 원격 위치에 업로드합니다. 그리고 버튼을 켤 때 다른 파일을 다시 업로드해야합니다. –

관련 문제