我需要帮助在两个aspx页面之间传递数据(这些aspx页面存储在SharePoint Designer中)。我创建了一些JavaScript,可以对我们网站上的指标进行一些简单的计算。
https://tandemhospitalpartners.sharepoint.com/SitePages/Home.aspx
以下JavaScript列在上面列出的aspx链接中。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
window.onload = function ()
{
}
function p1()
{
totalPts = 137;
setTotalPts(totalPts);
divId = document.getElementById('avg'); // element represents the ID 'countdown' for the div
today = new Date(); //this represents todays date in the following format
//Weekday ex. "Tue"
//Month ex. "Aug"
//Todays Date ex. "08"
//Year ex. "2017"
//Time ex. "13:44:54 GMT - 0500 (Central Daylight Time"
svOpen = new Date(2017, 06, 17); // this represents the first day we accepted patients
one_day = 1000 * 60 * 60 * 24;
//milliseconds
//minutes
//seconds
//hours
//We have been open for 23 days
daysOpen = Math.ceil((today.getTime() - svOpen.getTime()) / (one_day));
//subtracting SVNH open date from current date
avgPts = parseFloat(totalPts)/parseFloat(daysOpen);
divId.innerHTML ="Average Patients Per Day: "+ avgPts.toFixed(1);
}
function GetDays(element)
{
var el = document.getElementById(element);
today = new Date();
var cmas = new Date(today.getFullYear(), 6, 12);
if (today.getMonth() == 6 && today.getDate() > 13) {
cmas.setFullYear(cmas.getFullYear() + 1);
}
var one_day = 1000 * 60 * 60 * 24;
el.innerHTML =" Days to open the second Hospital: "+Math.ceil((cmas.getTime() - today.getTime()) / (one_day));
}
function setTotalPts(totalPts)
{
totId = document.getElementById("leOne");
totId.innerHTML = "This is my total patients: " + totalPts.toString();
}
</script>
</head>
<body onload="p1(); GetDays('count'); setTotalPts();"+"text"> <!-- this onload is passing the div ID to the function p1( element )
element represents the ID -->
<div id='count' style="color: #e51400 ;
font-weight : 500;"></div>
</body>
<body>
<div id='avg' style="color: #e51400 ;
font-weight : 500;"></div>
</body>
<body>
<div id='leOne' style="color: #e51400 ;
font-weight : 500;"></div>
</body>
</html>
<!-- to keep a running count of the days i will have to subtract svOpen from todaysDate
我的目标是将totalPts传递给另一个aspx文件上的HTML ID。
这是包含我想发送的HTML ID的aspx文件的链接。
https://tandemhospitalpartners.sharepoint.com/ININD/SitePages/Home.aspx
这是我真的很困惑的地方。我不确定如何实现这个结果。如果有人有关于如何使用JavaScript完成此操作的想法,我将非常感激!
答案 0 :(得分:1)
由于网络是无状态环境,因此您无法从其他网页的客户端访问其他网页的HTML。但是从第一页开始,您可以通过查询字符串将数据传递到下一页,也可以将数据保存到localStorage,然后导航到下一页并从localStorage检索数据。我更喜欢Querystring,因为它看起来只是你要传递的数字。
假设您有一个打开第二页的按钮
<asp:Button runat="server" ID="btnNext" OnClientClick="location.href='https://tandemhospitalpartners.sharepoint.com/ININD/SitePages/Home.aspx?totalPointes=' + getTotalPoints()" Text="Inind Home"></Button>
然后在目标页面中查询来自querystring的totalPoints并将其保存到元素中。 e.g。
$("#SomeID").val(getvaluefromQuerystring());
答案 1 :(得分:0)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$("#dvValue").html(getUrlParameter("totalPointes"));
});
//This function gets the querystring value from the querystring
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="dvValue"></div>
</div>
</form>
</body>
</html>