且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我的javascript出了什么问题

更新时间:2022-11-25 19:27:40

你在URL字符串上应用正则表达式。这就是你想要的吗?



我的猜测是你希望你把它应用到url页面的包含。

在这种情况下你必须先下载页面,然后将regex应用到页面,而不是URL。 br />


对于问题的加载部分,看起来解决方案取决于您使用的库(JQuery)和数据格式(html,xml,text) 。



在任何情况下,至少在制作时,我建议以易于测试零件的方式拆分程序。

确保每个部分分开工作,当一切正常时,你可以自信地组合在一起。



w3schools.com是一个自学的好地方。


Hi Experts,

function BtnSelect_Click_Complete(values) {
            var ofiledname;
            //alert('aaa');
            ofieldname = gup('fieldname');
            if (ofieldname != null) {
                //alert(ofieldname + " : " + values[0] + " : " + values[1]);
                window.opener.SetLookup(opener.document, ofieldname, values[0], values[1]);
                window.opener.PopulateParticipant(values[0], ofieldname);
            }
            self.close();
        }



function gup( name )
{
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var tmpURL = window.location.href;
    var results = regex.exec( tmpURL );
    if( results == null )
        return "";
  else
    return results[1];
}



tmpURL is getting : http://localhost:59037/ParticipantList
results is getting : ""

But result should get : either 'ComplainantID' or 'RespondentID'

I am totally stuck at this point. Please help me.

You apply the regex on URL string.Is it what you want ?

My guess is that you want you apply it to the contain of the page at url.
in this case you have to download the page first, and apply regex to the page, not the URL.

For the load part of the problem, it looks like the solution depend on which library you use (JQuery) and on the format of data (html, xml, text).

In any case, at least while making things, I recommend to split your program in a way that ease testing of parts.
Make sure each part works separately, when all works, you can put together confidently.

w3schools.com is a good place to go for self teaching.