我需要通过点击一个按钮来调用一个函数。按钮在aspx页面上,函数在.js页面上。这是我的按钮使用的代码:
<asp:LinkButton ID="lnkBTNSubmit" runat="server" CssClass="buttonlink"
OnClick="lnkBTNSubmit_Click" OnClientClick="onBtnSubmitClick();">Submit</asp:LinkButton>这是我的函数:
function onBtnSubmitClick() {
var startDate = document.getElementById('<%= txtATrendStartDate.ClientID %>').value;
var endDate = document.getElementById('<%= txtATrendEndDate.ClientID %>').value;
checkDateRange(startDate, endDate);
}
function checkDateRange(start, end) {
// Parse the entries
var startDate = Date.parse(start);
var endDate = Date.parse(end);
// Make sure they are valid
if (isNaN(startDate)) {
alert("The start date provided is not valid, please enter a valid date.");
return false;
}
if (isNaN(endDate)) {
alert("The end date provided is not valid, please enter a valid date.");
return false;
}
// Check the date range, 86400000 is the number of milliseconds in one day
var difference = (endDate - startDate) / (86400000 * 7);
if (difference < 0) {
alert("The start date must come before the end date.");
return false;
}
return true;
}请注意,该函数位于另一个.js页面上。
发布于 2012-03-28 13:50:19
要调用另一个js文件中的函数,必须在页面上包含对该js文件的引用。
示例:
把这个放到你的head标签里:
"script src="SomeOtherJSFIle.js" type="text/javascript"/script"https://stackoverflow.com/questions/9901789
复制相似问题