是否可以将 totalScore
var
传递给另一个页面 onclick
以便在那里显示?例如:点击提交链接,它会转到 yourscore.html 并在页面上显示分数
$("#process").click(function() {
var totalScore = 0;
$(".targetKeep").each( function(i, tK) {
if (typeof($(tK).raty('score')) != "undefined") {
totalScore += $(tK).raty('score');
}
});
alert("Total Score = "+totalScore);
});
最佳答案
让我们假设您的 HTML 可能如下所示:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#process").click(function() {
var totalScore = 0;
/*
Your code to calculate Total Score
Remove the next line in real code.
*/
totalScore = 55; //Remove this
alert("Total Score = "+totalScore);
$("#submit-link").attr('href',"http://example.com/yourscore.html?totalScore="+totalScore);
});
});
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<button id="process">Process</button>
<br />
<a href="#" id="submit-link">Submit Total Score</a>
</body>
</html>
看看这个 DEMO
在 yourscore.html 中,您可以在以下问题中了解更多信息,以从 URL 中提取 URL 参数:
关于javascript - 将 var 传递给另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18855680/