php - 单引号内的单引号 PHP

标签 php javascript variables quotes html-escape-characters

我有一个如下所示的 HTML achor 标签:

echo '<a href="javascript:tempBuy('.$res_get_price[0][0].','.$res_get_price[0][1].','.$res_get_price[0][2].','.$dt_str.')">'.$res_get_price[0][0];

对应的javascript函数tempBuy()是

function tempBuy(rate,veg_name,market_name,dt)
{
      alert(dt);
}

但问题是它根本不发出警报!可能我需要在 tempBuy() 中将变量名称包含在单引号内功能。我试过tempBuy(\'var1'\,\'var2\'...)但它显示错误。我怎样才能做到这一点。谢谢 。

该部分的来源如下所示:

<td width="120px" class=""><a href="javascript:tempBuy(56.0,Apple,Bangalore,2013-05-18)">56.0</a>                                
                                 </td>
                                <script>
                                    function tempBuy(rate,veg_name,market_name,dt)
                                    {
                                        alert(rate);

                                    }
                                </script>

最佳答案

您没有将 JavaScript 参数括在引号中。您需要将每个变量用单引号括起来,因为您对“href”属性使用了双引号。另一件事是您没有关闭“a”HTML 标记。

echo '<a href="javascript:tempBuy(\''.$res_get_price[0][0].'\',\''.$res_get_price[0][1].'\',\''.$res_get_price[0][2].'\',\''.$dt_str.'\')">'.$res_get_price[0][0].'</a>';

关于php - 单引号内的单引号 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16622034/

相关文章:

php - 处理 mysql 查询中的空/空白数据?

bash - Rundeck 跨作业步骤共享变量

javascript - 默认选择值在 Vue.js 中不起作用

javascript - Dygraphs div 在浏览器检查窗口打开之前不可见

javascript - Node.js 变量作用域

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

PHP 搜索/过滤功能

php - 如果 SplObjectStorage 在对象仍然附加的情况下破坏,它是否会留下内存泄漏引用?

php - 当您在用户注册时自动创建子域时,它会创建一个新网站还是提供一个网站的外观?

javascript - 无法弄清楚为什么 JS 会提示对象未定义