1

我有一个与我之前的问题类似的问题,但现在不同了

jquery:在 html 中显示进度条

  var auto_refresh = setInterval(
   function ()
  {
     $('#battery').load('https=://localhost/userinfo/battery_level/');

 }, 10000);

我不想加载 div ...我想得到结果并想在我的进度条中显示

 $('.demo-progress').progress(data);

我在这里得到一个值“10”

想做这样的事情

 var auto_refresh = setInterval(
   function ()
  {
    var data =  $('#battery').load('https=://localhost/userinfo/battery_level/');

 }, 10000);
      $('.demo-progress').progress(data);
4

1 回答 1

1

尝试这个:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" rel="Stylesheet" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>
        $(function () {
            $("#progressbar").progressbar({ max: 100, value: 10 });
            $("#twenty").click(function () { loadFile("20"); });
            $("#fifty").click(function () { loadFile("55"); });
            $("#eighty").click(function () { loadFile("80"); });
        });


        function loadFile(file) {
            $.get(file + ".txt", function (data) {
                var value = parseInt(data, 10);
                $('#progressbar').progressbar("option", "value", value);
            });
        }
    </script>
</head>
<body>
    <div id="progressbar">
    </div>
    <input type="button" id="twenty" value="Load to 20%" />
    <input type="button" id="fifty" value="Load to 50%" />
    <input type="button" id="eighty" value="Load to 80%" />
</body>
</html>

从 jquery 页面:

此方法 (.load) 是从服务器获取数据的最简单方法。它大致相当于 $.get(url, data, success) ,只是它是一个方法而不是全局函数,并且它具有隐式回调函数。

我使用 .get 的原因是因为最后一部分,隐式回调函数,它让我知道函数何时结束,然后我可以更新进度条。

于 2013-08-16T20:47:44.463 回答