我的JavaScript代码有什么问题? [英] What's wrong in my JavaScript code?

查看:88
本文介绍了我的JavaScript代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我编写的JavaScript函数应该返回值。但它没有生成完整的QueryString。它正在为正在调用它的另一个页面生成并返回值。对于我的特定页面,它正在调用,但不幸的是变为空。



请帮助我,我需要在几个小时内不惜一切代价解决这个问题。提前致谢。变量的代码和输出如下:

 ofieldname = gup(' 字段名'); 

function gup(name){

var regexS = [\\?&] + name + =([^ ] *);
var regex = new RegExp (正则表达式);
var tmpURL = window location .href;
// alert(tmpURL);
var results = regex.exec(tmpURL);
if (results == null
返回 ;
else
return 结果[ 1 ];
}

regexS输出:[\?&] fieldname =([^ ] *)
正则表达式输出:[\?&] fieldname =([ ^ ] *)
tmpURL输出:http: // localhost:59037 / MediatorList
结果输出: null

解决方案

嗯...你的URL与您的Regex不匹配:正则表达式要求匹配字符串以反斜杠,问号或&符号开头 - 并且您的URL不包含这些内容。因此正则表达式无法匹配,并返回null。



我认为你需要重新思考你在做什么 - 因为我不知道那个正则表达式是什么意思做!

Hi Experts,

I have written JavaScript function which should return the value. But it is not generating the complete QueryString. It is generating and returning value for another page where it is being called. For my particular page it is calling but unfortunately getting null.

Please help me, I need to solve this issue in few hours at any cost. Thanks in advance. Code and output of variables are below:

ofieldname = gup('fieldname');

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

regexS output: [\?&]fieldname=([^�]*)
regex output: [\?&]fieldname=([^�]*)
tmpURL output: http://localhost:59037/MediatorList
results Output: null

解决方案

Um...your URL doesn't match your Regex: the regex demands the match string starts with a backslash, question mark, or ampersand - and your URL contains none of these. So the regex fails to match, and returns a null.

I think you need to rethink what you are doing - because I have no idea what that regex is intended to do!


这篇关于我的JavaScript代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆