gpt4 book ai didi

javascript - 函数的返回值返回未定义

转载 作者:行者123 更新时间:2023-12-02 20:17:28 25 4
gpt4 key购买 nike

尝试从 getUrl 函数获取返回值,但返回结果为未定义。
我将不胜感激任何帮助。

谢谢
这是代码:

    function createXmlFicaRsi(xmlDoc,xmlFileName) {     
var mystr = "<?xml version='1.0' encoding='utf-8'?><result><rows>"+strStor+"</rows></result>"
jQuery(document).ready(function(){
jQuery("#fRsiGrid").jqGrid({
datatype: 'xmlstring',
datastr : mystr,
colNames:['Year','Earnings', 'Amt<br/>Needed <br/>1 QC','Amt<br/>Needed <br/>4 QC','#<br/>of<br/> QCs','Monthly<br/>Under FRA','Yearly<br/>Under FRA','Monthly<br/> Yearly of<br/> Attain.<br/> FRA','Year of<br/> Attain. of<br/> FRA','YOC*','Sum of<br/>Post-1977<br/>YOCs'],
colModel :[
{name:'yearRsi', index:'yearRsi', width:55, resizable:false, align:'center', sorttype:'int'},
{name:'earnRsi', index:'earnRsi', width:65, resizable:false, align:'right', sortable:false},
{name:'1qcRsi', index:'1qcRsi', width:65, resizable:false, align:'right', sortable:false},
{name:'4qcRsi', index:'4qcRsi', width:65, resizable:false, align:'right', sortable:false},
{name:'numqcRsi', index:'numqcRsi', width:40, resizable:false, align:'right', sortable:false},
{name:'mfra', index:'mfra', width:65, resizable:false, align:'right', sortable:false},
{name:'yfra', index:'yfra', width:65, resizable:false, align:'right', sortable:false},
{name:'myafra', index:'myafra', width:85, resizable:false, align:'right', sortable:false},
{name:'yafra', index:'yafra', width:65, resizable:false, align:'right', sortable:false},
{name:'yoc', index:'yoc', width:65, resizable:false, align:'right', sortable:false},
{name:'sumpost', index:'sumpost', width:60, resizable:false, align:'right', sortable:false} ],
rowNum:-1,
hidegrid: false,
width: 760,
height: 460,
shrinkToFit: false,
caption: '<span id=fRsiGrid_caption>FICA Earnings, QC, AET and YOC amounts after 1977</span>'
});

$('.ui-jqgrid .ui-th-column').css('height', '40px');
$('.ui-jqgrid .ui-jqgrid-htable th div').css('height', '40px');
$('.ui-jqgrid-title').css('font-size', '.8em');//Font size for title
$('.ui-jqgrid .ui-th-column').css('font-size', '.7em');//Font size for header content
$('#fRsiGrid_caption').append("<span id='whatLink' style='font-size:large;color:blue;text-decoration:none;cursor:pointer'>*</span>");

});
$('#jqgh_1qcRsi').addClass("gridLink");
$('#jqgh_4qcRsi').addClass("gridLink");
$('#jqgh_mfra').addClass("gridLink");
$('#jqgh_yfra').addClass("gridLink");
$('#jqgh_myafra').addClass("gridLink");
$('#jqgh_yafra').addClass("gridLink");
$('#jqgh_yoc').addClass("gridLink");

$("#jqgh_1qcRsi").click(function() {
var nurl = getUrl("QueryView-QC");
alert(nurl);
});
}

function getUrl(urlNm){
DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getUrls', urlNm, doQueryResults);
function doQueryResults(r){
xmlDoc = loadXMLString(r);
y = xmlDoc.getElementsByTagName("URL");

for (i = 0; i < y.length; i++) {
url = y[i].attributes.getNamedItem("val").nodeValue;
if (url == urlNm)
{
url = y[i].childNodes[0];
//alert(url.nodeValue);
url = url.nodeValue;
return url;
}
}
}
}

最佳答案

您正在返回内部函数,但 getURL 函数没有返回任何内容。

function getUrl(urlNm){
DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getUrls', urlNm, doQueryResults);
var returnVal = function doQueryResults(r){
xmlDoc = loadXMLString(r);
y = xmlDoc.getElementsByTagName("URL");

for (i = 0; i < y.length; i++) {
url = y[i].attributes.getNamedItem("val").nodeValue;
if (url == urlNm)
{
url = y[i].childNodes[0];
//alert(url.nodeValue);
url = url.nodeValue;
return url;
}
}
}
return returnVal;
}

关于javascript - 函数的返回值返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com