将div值传递给JQuery Progress Bar

时间:2013-08-14 11:15:46

标签: jquery progress-bar

我的HTML有一个输出数字的div(#user_info)。我想在jQuery Progress Bar中使用该数字,所以我使用CSS隐藏了数字并包括以下内容:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<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>
<link rel="stylesheet" href="/resources/demos/style.css" />

<div id="progressbar"></div>

<script>

$(function() {
    var valor=parseInt($("#user_info").val(), 10);;
    alert(valor);
    $( "#progressbar" ).progressbar({
    value: valor
});
});

</script>

为什么警报功能输出“NaN”,因此进度条为空?

1 个答案:

答案 0 :(得分:0)

试试这个

var valor=parseInt($("#user_info").text(), 10);

您可以在输入中使用.val()。对于div,你应该使用.text()或.html()。

相关问题