duanqu9292 2013-05-15 18:44
浏览 88
已采纳

复选框在刷新/提交后保持检查状态

if so to trigger a js function. I can make a checkbox stay checked with value and checked="checked" on page refresh and for my submit the following...

 <input type="checkbox" name="check" value="checked" 
 <?php if($_POST['check'] ==    'checked'): ?>checked="checked"<?php endif; ?> />

thou neither of this remember to trigger the js function.

Here is my function and what I try to accomplish. http://jsfiddle.net/melbourne/s5AXZ/

My only choices are what Im asking you or to show and post new comments via ajax.. still the refresh problem will remain but the refresh will not be needed so much. In a nutshell Im sticking with my first question since ajax posting and showing new comments its out of my league. Thanks.

  • 写回答

1条回答 默认 最新

  • duangang3832 2013-05-15 18:56
    关注

    Your question is kind of messy, but from what I understand do you wish to fire the .change-method if the checkbox is checked at load.

    I'd suggest you just do the same php-if on the parent-element (the one you are adding the night-class to).

    Something like:

    <?php if($_POST['check'] == 'checked') echo 'class="night"'; ?>
    

    It is much better to fix this at serverside when you already know the changes you wish to do.

    BUT, if you want to do this with only js, you can do it like this:

    function initBackground() {
        if ($('#btn').is(':checked')) {
            $('#btn').parent().toggleClass('night');
        }
    }
    
    $(document).ready(function () {
        initBackground();
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)