【问题标题】:Is there a JavaScript equivalent to "string" . "string" in PHP?是否有等效于 "string" 的 JavaScript。 PHP中的“字符串”?
【发布时间】:2014-05-20 11:36:14
【问题描述】:

我目前正在学习一点 JavaScript 并有一个问题。

在 PHP 中,我习惯于用一个简单的点将文本和字符串绑定在一起,如下所示:

echo "Text" . $String . "anotherText" . $anotherString

这在 JavaScript 中可行吗? (不是回声,而是字符串和文本的绑定。)

【问题讨论】:

  • 只是谷歌搜索提示:> dot operator php 应该会导致术语 concatenation -> javascript concatenation 会找到你的答案。

标签: javascript php concatenation string-concatenation


【解决方案1】:

+ is the concatenation operator in JavaScript:

"Text" + somestring + "anotherText" + anotherString;

【讨论】:

  • 我认为document.write 是不必要的
  • document.write 或多或少相当于 PHP 中的 echo 的 JavaScript。
【解决方案2】:

在 JavaScript 中是 + 而不是 .

示例 1:

document.write("Text" + somestring + "anotherText" + anotherString);

示例 2:

alert("Text" + somestring + "anotherText" + anotherString);

示例 3:

var john = "Text" + somestring + "anotherText" + anotherString;

【讨论】:

    【解决方案3】:

    是的,添加:

    'Text' + str + 'anotherText' + anotherString;
    

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-11-05
      • 2016-04-25
      相关资源
      最近更新 更多