Jquery脚本在浏览器中不起作用

时间:2016-01-12 14:54:15

标签: javascript jquery

我曾尝试从Stackoverflow添加一个需要很长时间才能获得的脚本, 但似乎文件对我不利,尽管它工作得很好 在JSfiddle很好。 http://jsfiddle.net/hqtsmayh/

<div data-role="page" id="page1">
    <div data-role="header">
         <h1>My page</h1> 
    </div>
    <div role="main" class="ui-content">
        <div id="mysliders">
            <label for="slider-1">Slider:</label>
            <input class="add" type="range" name="slider-1" id="slider-1" min="0" max="100" value="50" />
            <label for="slider-2">Slider:</label>
            <input class="add" type="range" name="slider-2" id="slider-2" min="0" max="100" value="40" />
            <label for="slider-3">Slider:</label>
            <input class="add" type="range" name="slider-3" id="slider-3" min="0" max="100" value="30" />
            <label for="slider-4">Slider:</label>
            <input class="add" type="range" name="slider-4" id="slider-4" min="0" max="100" value="65" />
            <label for="slider-5">Slider:</label>
            <input class="add" type="range" name="slider-5" id="slider-5" min="0" max="100" value="11" />
            <label for="slider-6">Slider:</label>
            <input class="add" type="range" name="slider-6" id="slider-6" min="0" max="100" value="90" />
        </div>
        <hr />
        <p>Total: <strong id="total"></strong></p>
    </div>
    <div data-role="footer" data-position="fixed">
         <h1>Footer</h1> 
    </div>
</div>
<script>
    $(window).load(function(){
            $(document).on("pagecreate", "#page1", function () {
                $(".add").on("change", function () {
                    addAll();
                });

                addAll();
            });

            function addAll() {
                var sum = 0
                $('.add').each(function (){        
                    sum += isNaN(this.value) || $.trim(this.value) === '' ? 0 : parseFloat(this.value);        
                });
                $('#total').html(sum);
            }
    });
</script>

标题中的所有内容都是Jquery附件:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

1 个答案:

答案 0 :(得分:0)

为什么不呢?在移动Safari中测试

还要注意jsFiddle的默认onload

&#13;
&#13;
$(window).load(function() {
    $(".add").on("change", function() {
      addAll();
    });
    addAll();
  });

  function addAll() {
    var sum = 0
    $('.add').each(function() {
      sum += isNaN(this.value) || $.trim(this.value) === '' ? 0 : parseFloat(this.value);
    });
    $('#total').html(sum);
  }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div data-role="page" id="page1">
  <div data-role="header">
    <h1>My page</h1> 
  </div>
  <div role="main" class="ui-content">
    <div id="mysliders">
      <label for="slider-1">Slider:</label>
      <input class="add" type="range" name="slider-1" id="slider-1" min="0" max="100" value="50" />
      <label for="slider-2">Slider:</label>
      <input class="add" type="range" name="slider-2" id="slider-2" min="0" max="100" value="40" />
      <label for="slider-3">Slider:</label>
      <input class="add" type="range" name="slider-3" id="slider-3" min="0" max="100" value="30" />
      <label for="slider-4">Slider:</label>
      <input class="add" type="range" name="slider-4" id="slider-4" min="0" max="100" value="65" />
      <label for="slider-5">Slider:</label>
      <input class="add" type="range" name="slider-5" id="slider-5" min="0" max="100" value="11" />
      <label for="slider-6">Slider:</label>
      <input class="add" type="range" name="slider-6" id="slider-6" min="0" max="100" value="90" />
    </div>
    <hr />
    <p>Total: <strong id="total"></strong>
    </p>
  </div>
  <div data-role="footer" data-position="fixed">
    <h1>Footer</h1> 
  </div>
</div>
&#13;
&#13;
&#13;