dqb14659 2014-03-23 00:19
浏览 23
已采纳

PHP页面加载后,我无法动态更改javascript中的值

In my code below, I want to change the initial value with a slider. The slider works and everything, but it's not changing the values of the timeout, shown under the $('ul.<?php echo $this->session->userdata('username'); ?>').innerfade({ line.

The value of slider in the line $('#ex1').on('slide', function(slider) is equal to the value of the input-form attribute data-slider-value which is 100.

Now, when I start to adjust the input slider, it will change the attribute from its initial value of 100 to whatever the user slides to.

But the problem is, the slider won't change the values inside the jquery code...


So to make it more clear:

In the JS code, the variable 'value' is declared, but not yet initialized to a value.

The variable 'value' is then assigned to 'slider.value'

And so the logical conclusion is that the 'timeout' variable should change dynamically, according to the values inputted by the slider.

<!-- Start slider -->
<p>
    <input id="ex1" data-slider-id='ex1Slider' type="text" data-slider-min="1" data-slider-max="1000" data-slider-step="1" data-slider-value="100"/>
</p>

<script type="text/javascript">
    $(document).ready(
    function(){
        var value;

        $('#ex1').slider();
        $('#ex1').on('slide', function(slider)
        {
            value = slider.value;
        });

        $('ul.<?php echo $this->session->userdata('username'); ?>').innerfade({
            speed: 0,
            timeout: value,
            type: 'sequence',
            containerheight: '480px'
        });
    });
</script>
  • 写回答

3条回答 默认 最新

  • douza19870617 2014-03-23 00:27
    关注

    It's normal, your animation is already made. Your have to remake your animation or better, change the option.

    edit :

    There is the idea (not sure if is the correct syntax) :

    //make it
    var usernameInnerFace = $('ul.<?php echo $this->session->userdata('username'); ?>').innerfade({
        speed: 0,
        timeout: value,
        type: 'sequence',
        containerheight: '480px'
    });
    
    //change it
    usernameInnerFace.options['timeout'] = new_value;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来