2014-09-22 132 views
0

我想使用jquery里程錶在母版頁上顯示信息。 http://www.jqueryscript.net/animation/Smooth-Animated-Numbers-with-Javascript-CSS3-odometer.html使用Odometer將變量傳遞給jquery

爲了做到這一點,我必須從SQL Server使用C#中檢索該值。然後我必須將它傳遞給html()中的jscript里程錶,如下所示。如果我獲得了價值 - 如何將它發送給javascript?

<script> 
     setTimeout(function(){ 
     $('.odometer').html('123222'); 
     }, 1000); 
    </script> 
+0

ajax調用怎麼樣? – 2014-09-22 08:14:27

回答

0

您可以使用下面的實現來通過從代碼背後的價值將jQuery

這是一個例子,如何做到這一點。

首先聲明一個公共變量在後面的代碼

//聲明在代碼中的公共變量背後

public string odometervalue = "667"; 

閱讀下面

<script> 
     $(function() { 
      setTimeout(function() { 
       //Get the value from serverside 
       var uid = '<%=odometervalue %>'; 
       odometer.innerHTML = uid; 
      }, 1000); 
     }); 

    </script> 
1

給jQuery中像值試試這個網站

</head> 
<body> 

<script src="https://rawgit.com/HubSpot/odometer/v0.4.6/odometer.min.js"></script> 
<style src="https://rawgit.com/HubSpot/odometer/master/themes/odometer-theme-default.css"></style> 

<script> 
    odometerOptions = { 
    auto: false 
}; 
</script> 

<script type = "text/javascript"> 
    $(function(){ 
    var exampleOdometerValue = 123456; 
    var exampleOdometer = new Odometer({ el: $('.odometer-example')[0], theme: 'digital', value: exampleOdometerValue }); 
    exampleOdometer.render() 

    setTimeout(function(){ 
     exampleOdometerValue = exampleOdometerValue+100.07; 
     exampleOdometer.update(exampleOdometerValue); 
    }, 2000); 

    }); 
</script> 
<div class="odometer odometer-example">123</div> 

</body></html>