gpt4 book ai didi

Javascript 如何将变量放入 URICOMPONENT

转载 作者:行者123 更新时间:2023-12-02 19:11:06 25 4
gpt4 key购买 nike

var frank_param = gup( 'frank' );
var pageURL = encodeURIComponent("directory_doctor_page.php?DoctorID=23");

我有这两行代码,我想用 var Frank 替换 23。我将如何实现这一目标?

谢谢

最佳答案

您可以像这样连接两者:

var pageURL = encodeURIComponent("directory_doctor_page.php?DoctorID=" + frank_param); 

摘自 mozilla 的 JS 文档 String operators :

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".

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.

关于Javascript 如何将变量放入 URICOMPONENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13698906/

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