本文介绍了JavaScript函数不返回值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在外部JavaScript页面中有一个JavaScript函数。功能如下。 Script.js function getVaria(){ strStartDate = document .getElementById( from_date)。value; strEndDate = document .getElementById( to_date 。)值; // 以下变量将是对第一个图表的查询。 strWsUrl = https://www.googleapis.com/analytics/v3/data/ga?ids= ga%3A76546294& dimensions = ga%3Asource& metrics = ga%3Ausers& filters = ga%3Asource!%3D(direct)& sort = -ga%3Ausers& start-date ='+ strStartDate +'& end-date ='+ strEndDate +'& max-results = 10; alert(strStartDate); alert(strEndDate); alert(strWsUrl); return strWsUrl; } 此函数应该'返回strWsUrl '。为了获取该值,我在该特定外部JavaScript页面之外创建了另一个函数。它在下面。 Dashboard.html < script 类型 = text / javascript src = js / script.js > < / script > < script type = text / javascript > // 日期选择器 $( function (){ $( #to_date)。datepicker({maxDate : new 日期()}); $( #from_date)。datepicker({maxDate: new 日期()}); $( div.ui-datepicker)。css({ font-size: 10px}); }); < / script > < 脚本 类型 = text / javascript > function myTest(){ getVaria(); alert( 这是UI页面 + strWsUrl); } 但结果是这是UI页面未定义。我认为这是因为strWsUrl值没有传递给HTML页面。那么我做错了什么? 有人可以帮我解决这个问题吗? Chiranthaka 解决方案 ( function (){ ( #to_date)。datepicker({maxDate: new 日期()}); ( #from_date)。datepicker({maxDate: new Date ()}); I have a JavaScript Function in an external JavaScript page. The function is at the below.Script.jsfunction getVaria(){strStartDate = document.getElementById("from_date").value;strEndDate = document.getElementById("to_date").value;//Following variable will be the query to the 1st chart.strWsUrl = "https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date=' + strStartDate + '&end-date=' + strEndDate + '&max-results=10";alert(strStartDate);alert(strEndDate);alert(strWsUrl);return strWsUrl;}This function shaould 'return strWsUrl'. To grab that value I have created another function outside of that perticular external JavaScript page. It is at below.Dashboard.html<script type="text/javascript" src="js/script.js"></script><script type="text/javascript">//Date Picker$(function() {$("#to_date").datepicker({ maxDate: new Date() });$("#from_date").datepicker({ maxDate: new Date() });$("div.ui-datepicker").css( { "font-size": "10px" } );});</script><script type="text/javascript">function myTest(){getVaria();alert("This is UI Page " + strWsUrl);}However the result is This is UI Page Undefined. I think this is because the strWsUrl value does not pass to the HTML page. So What have I done wrong?Could someone enlight me to solve the matter?Chiranthaka 解决方案 (function() {("#to_date").datepicker({ maxDate: new Date() });("#from_date").datepicker({ maxDate: new Date() }); 这篇关于JavaScript函数不返回值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-18 13:43