[英]Javascript how to put variable in a URICOMPONENT
var frank_param = gup( 'frank' );
var pageURL = encodeURIComponent("directory_doctor_page.php?DoctorID=23");
I have those two lines of code I want to replace the 23 with the var frank. 我有两行代码我想用var frank替换23。 How will I accomplish this?
我将如何做到这一点?
Thanks 谢谢
You can concatenate both like this: 你可以这样连接:
var pageURL = encodeURIComponent("directory_doctor_page.php?DoctorID=" + frank_param);
Extract from mozilla's JS documentation on String operators : 从字符串运算符的 mozilla JS文档中提取:
In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.
除了可以在字符串值上使用的比较运算符之外,连接运算符(+)将两个字符串值连接在一起,返回另一个字符串,该字符串是两个操作数字符串的并集。 For example, "my " + "string" returns the string "my string".
例如,“my”+“string”返回字符串“my string”。
The shorthand assignment operator += can also be used to concatenate strings.
简写赋值运算符+ =也可用于连接字符串。 For example, if the variable mystring has the value "alpha", then the expression mystring += "bet" evaluates to "alphabet" and assigns this value to mystring.
例如,如果变量mystring的值为“alpha”,则表达式mystring + =“bet”计算为“alphabet”并将此值赋给mystring。
You can simply concatenate the variable to the string: 您可以简单地将变量连接到字符串:
var frank_param = gup( 'frank' );
var pageURL = encodeURIComponent("directory_doctor_page.php?DoctorID=" + frank_param );
I'd suggest taking a look at some JavaScript Tutorials , on the StackOverflow FAQ. 我建议在StackOverflow FAQ上查看一些JavaScript教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.