2012-03-28 55 views
0

我需要通過單擊按鈕來調用一個函數。按鈕位於一個aspx頁面上,並且該函數位於一個.js頁面上。 這是我用我的按鈕 提交從按鈕點擊事件調用另一個位置的功能

代碼,這是我的功能

功能onBtnSubmitClick(){ VAR的startDate =的document.getElementById( '<%= txtATrendStartDate.ClientID%>')。值; 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文件page..thank你提前

回答

0

調用的函數在其他JS文件,你必須包含JS文件的引用您 頁EX: 在你的頭標記將這個: 「腳本SRC =」 SomeOtherJSFIle.js「類型=‘文/ JavaScript的’/腳本」

+0

包括圍繞腳本標籤的加價括號..我不能讓它顯示在帖子中:-)一旦引用完成,你可以像任何ot一樣調用函數她的功能 – TGH 2012-03-28 05:52:41

+0

thanx爲響應...但事情沒什麼反應,當我點擊按鈕...我的按鈕代碼是提交 ..我做錯了什麼? – nitinvertigo 2012-03-28 06:00:58

+0

也當我保持在同一頁面的功能..它完美的作品 – nitinvertigo 2012-03-28 06:03:02

相關問題