本文介绍了带返回传递值的JavaScript多函数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了3个JavaScript函数。第一个2将返回2个值,我希望第三个函数获取这些值。



I have created 3 JavaScript Functions. The 1st 2 will return 2 values and I want the 3rd function to grab those values.

function retStartDate(){
var strStartDate = document.getElementById("from_date").value;
alert(strStartDate);

return strStartDate;

}

function retEndDate(){
var strEndDate = document.getElementById("to_date").value;
alert(strEndDate);
return strEndDate;

}

function getVaria(){

var 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= retStartDate() &end-date= retEndDate() &max-results=10';

alert(strWsUrl);

return strWsUrl;

}





现在你可以看到getVaria()有一个变量strWsUrl&因为我已经放置了返回strStartDate&的2个函数。 strEndDate如下所示。





Now you can see getVaria() has a variable strWsUrl & in that I have placed the 2 functions that return strStartDate & strEndDate as the below.

var 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= retStartDate() &end-date= retEndDate() &max-results=10';





但是当我提醒我得到了以下结果时。



https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource !%3D(直接)& sort = -ga%3Ausers& start-date = retStartDate()& end-date = retEndDate()& max-results = 10



但是正确的警报必须包含两个日期的开始日期和时间。结束日期。



你能猜出我做错了吗?如果是这样,请尝试发布解决方案。



谢谢&问候,

Chiranthaka。



But when I alert that I got the follwoing result.

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= retStartDate() &end-date= retEndDate() &max-results=10

But the correct alert must be with two dates for start-date & end-date.

Can you someone guess what I have done wrong? If so please try to post the solution.

Thanks & regards,
Chiranthaka.

推荐答案

function getVaria(){

var 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= '+ retStartDate() + '&end-date=' + retEndDate() + '&max-results=10';

alert(strWsUrl);

return strWsUrl;

}





希望这个帮助: - )



Hope this help :-)


这篇关于带返回传递值的JavaScript多函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 06:54