JavaScript将函数的变量传递给函数 [英] Javascript passing variable from function to function
问题描述
如何将 var rating 和 var itervalue 传递到我的window.location.replace?我从函数updateRating()获得新的评级变量,当我点击hireraccept时,它指定一个新的itervalue变量,我希望将它们都传递给window.location.replace url中的继续按钮。任何想法?
How do i pass var rating and var itervalue into my window.location.replace? i get new rating variable from function updateRating() and when i click hireraccept, it assigns a new itervalue variable which i wish to pass them both into the "proceed" button into the window.location.replace url. any idea?
<script type="text/javascript">
$(document).ready(function(){
var rating = 0;
var itervalue = 0;
$(".hireraccept").click(function(){
$('.jRating').jRating();
$("#dialog-rate").dialog("open");
var itervalue = $(this).attr("value");
return false
});
$("#dialog-rate").dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Proceed": function(){
window.location.replace("{{ domain_url }}/workroom/accept/" + itervalue +"/" + rating);
$(this).dialog("close");
}
}
});
});
</script>
<script type="text/javascript">
function updateRating(rate,proceed){
goodtogo = proceed;
rating = rate;
}
</script>
推荐答案
你的iterval是全局声明的,但是重新声明它本地。从您的点击处理程序中删除var声明,它将覆盖全局值,然后您可以在对话框打开选项中使用它。
You have your iterval declared globally, but then redeclare it locally. Remove the var declaration from your click handler and it will overwrite the global value, which you can then use in your dialog opening options.
//编辑
更改这个
// edit Change this
var itervalue = $(this).attr("value");
为此,这应该是工作的
to this, and that should work
itervalue = $(this).attr("value");
这篇关于JavaScript将函数的变量传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!