[英]c# - Pass variable to javascript in a OnClick function - Progress Bar
I have a button and when i click on the button I launch a javascript function (progress bar) 我有一个按钮,当我单击该按钮时,我启动了一个javascript函数(进度条)
<asp:Button ID="btn_tel" runat="server" CausesValidation="False" OnClick="btn_telefono" Text="Controlla" CssClass="button" OnClientClick="move()" /></div>
Function move(): 函数move():
<script type="text/javascript">
function move() {
setTimeout(function () {
var elem = document.getElementById("myBar");
elem.style.color = "White";
var width = 0;
var temp= "<%=intervallo%>";
var id = setInterval(frame, temp);
function frame() {
if (width >= 100) {
clearInterval(id);
} else {
width++;
elem.style.width = width + '%';
elem.innerHTML = width * 1 + '%';
}
}
}, 0)
}
</script>
In my code I can set the variable "intervallo" . 在我的代码中,我可以设置变量“ intervallo” 。
The code works, but i want to pass the variable intervallo when i click on the button. 该代码有效,但是我想在单击按钮时传递变量intervallo 。
I tried in several ways but I did not succeed. 我尝试了几种方法,但没有成功。 Do you have any idea?
你有什么主意吗?
Thanks 谢谢
I believe the easiest way is to add a parameter to your function: 我相信最简单的方法是向函数添加参数:
function move(var x) {
...
}
Then, in the page call the method with: 然后,在页面中使用以下方法调用方法:
...onClientClick="move(x)"
Replace x in the method call with the value you want to pass to the function. 用要传递给函数的值替换方法调用中的x。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.