如何从Default.aspx.cs调用jQuery函数 [英] How do I call a jQuery function from Default.aspx.cs
本文介绍了如何从Default.aspx.cs调用jQuery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从Default.aspx.cs调用jQuery函数?
Default.aspx.cs
var 进度= 20跨度>;
ScriptManager.RegisterClientScriptBlock( this , this .GetType(), scr, setProgress( + Progress + );,真跨度>);
错误代码:
JavaScript运行时错误:'setProgress'未定义
Default.aspx
< script src = http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js > < / 脚本 >
< script type = text / javascript >
$(文档)。ready( function (){
function setProgress (进度){
var progressBarWidth = progress * $( 。container)。width()/ 100 ;
$( .progressbar)。width(progressBarWidth).html(progress + < span class =code-string> %);
}
( function ($){
$ .fn.progressbar = function (选项){
var settings = $ .extend({
width: ' 300px',
height:' 25px',
color:' #0ba1b5',
padding:' 0px',
border:' 1px solid #ddd'
},options);
// 将css设置为容器
$( this )。css({
' width':settings.width,
' border':settings。 border,
' border-radius': ' 5px',
' overflow':' hidden',
' display':' inline-block',
' padding':settings.padding,
' margin':' 0px 10px 5px 5px'
});
// 将进度条添加到容器
var progressbar = $( < div>< / div> 跨度>);
progressbar.css({
' height':settings.height,
' text-align':' right',
' vertical- align':' middle',
' color':' #fff',
' width':' 0px',
' 边界半径:' 3px',
' background-color':settings.color
});
$( this )。append(progressbar);
此 .progress = function (value){
< span class =code-keyword> var width = $( this )。width()* value / 100 跨度>;
progressbar.width(width).html(value + %);
}
返回 此;
};
}(jQuery));
});
< / script >
解决方案
( document )。ready( function (){
function setProgress(progress ){
var progressBarWidth = progress *
( 。container)。width()/ 100 ;
< blockquote>( .progressbar)。width(progressBarWidth).html(progress + %);
}
( function (
How do I call a jQuery function from Default.aspx.cs?
Default.aspx.cs
var Progress = "20";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scr", "setProgress(" + Progress + ");", true);
Error Code:
JavaScript runtime error: 'setProgress' is undefined
Default.aspx
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
function setProgress(progress) {
var progressBarWidth = progress * $(".container").width() / 100;
$(".progressbar").width(progressBarWidth).html(progress + "% ");
}
(function ($) {
$.fn.progressbar = function (options) {
var settings = $.extend({
width: '300px',
height: '25px',
color: '#0ba1b5',
padding: '0px',
border: '1px solid #ddd'
}, options);
//Set css to container
$(this).css({
'width': settings.width,
'border': settings.border,
'border-radius': '5px',
'overflow': 'hidden',
'display': 'inline-block',
'padding': settings.padding,
'margin': '0px 10px 5px 5px'
});
// add progress bar to container
var progressbar = $("<div></div>");
progressbar.css({
'height': settings.height,
'text-align': 'right',
'vertical-align': 'middle',
'color': '#fff',
'width': '0px',
'border-radius': '3px',
'background-color': settings.color
});
$(this).append(progressbar);
this.progress = function (value) {
var width = $(this).width() * value / 100;
progressbar.width(width).html(value + "% ");
}
return this;
};
} (jQuery));
});
</script>
解决方案
(document).ready(function () { function setProgress(progress) { var progressBarWidth = progress *
(".container").width() / 100;
(".progressbar").width(progressBarWidth).html(progress + "% "); } (function (
这篇关于如何从Default.aspx.cs调用jQuery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文