【问题标题】:how to insert uniqid() in javascript [duplicate]如何在javascript中插入uniqid()[重复]
【发布时间】:2015-12-08 13:30:03
【问题描述】:

我正在尝试将 uniqid() 绑定到字符串中的 onclick 事件:

$UniquepreID = uniqid();
$selectbutton = '<input type="button" value="testabc" 
       onclick="selectElementContents( document.getElementById("$UniquepreID") );" />';

$UniquepreID 是按字面意思解析的。我怎样才能使它正常工作?

【问题讨论】:

    标签: php uniq


    【解决方案1】:

    您的$UniquepreID 在单引号内,因此不会被扩展。 See here

    试试这个:

    $selectbutton = '<input type="button" value="testabc" onclick="selectElementContents( document.getElementById("' . $UniquepreID . '") );" />';
    

    【讨论】:

    • 谢谢!现在可以使用了
    【解决方案2】:

    您使用单引号来定义字符串变量$selectbutton。 您必须使用双引号或像这样使用您的字符串:

    $selectbutton = 'some string with "quotes"' . $uniquepreID . 'more "quotes" here';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 2011-06-19
      • 2013-08-04
      • 2014-11-21
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多