Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将我的数据库值作为字符串传递给我的javascript函数PHP_Javascript_Php_Function_Mysqli - Fatal编程技术网

将我的数据库值作为字符串传递给我的javascript函数PHP

将我的数据库值作为字符串传递给我的javascript函数PHP,javascript,php,function,mysqli,Javascript,Php,Function,Mysqli,我的数据库中有一个字符串值,它是id,我还有一个带有javascript函数的按钮onclick=“values('argument')” 我的问题是,当我尝试单击该按钮时,出现以下错误: (index):1 Uncaught ReferenceError: argument is not defined 我知道发生这种情况是因为参数未被视为字符串 如何将参数作为字符串传递 所有这些都是一个包含在php函数中的表,该函数显示来自我的数据库的信息 这是我的完整代码 <?php

我的数据库中有一个字符串值,它是id,我还有一个带有javascript函数的按钮onclick=“values('argument')

我的问题是,当我尝试单击该按钮时,出现以下错误:

(index):1 Uncaught ReferenceError: argument is not defined
我知道发生这种情况是因为参数未被视为字符串

如何将参数作为字符串传递

所有这些都是一个包含在php函数中的表,该函数显示来自我的数据库的信息

这是我的完整代码

    <?php


   function oportunities($resultQuery)
   {

    echo '<div class="table-responsive">
                <table class="responstable">
                    <thead class="thead">

                    <tr>
                        <th>No.</th>
                        <th>value1</th>
                        <th>value2</th>
                        <th>value3</th>
                        <th>value4</th>
                        <th>value5</th>
                        <th>value6</th>
                        <th>value7</th>
                        <th>value8</th>
                        <th>value9</th>
                        <th>value10</th>
                        <th>value11</th>
                        <th>value12</th>
                        <th>value13</th>
                        <th>value14</th>
                        <th>value15</th>
                    </tr>

                    </thead>
                    <tbody>';

    foreach($resultQuery as $row){
        echo '<tr>
                <td> '. $row['id'] .'</td>
                        <td>'. $row['value1'] .'</td>
                        <td>'.  $row['value2'] .'</td>
                        <td class="descripcion">
                            <p class="text-descripcion">'.$row['value3'].' </p>
                        </td>
                        <td> '.$row['value4'].' </td>
                        <td> '. $row['value5'].' </td>
                        <td><p class="text-center">'. $row['value6'] .'% </p></td>
                        <td> '.$row['value7'].' </td>
                        <td> '.$row['value8'].' </td>
                        <td> '.$row['value9'].' </td>
                        <td> '.$row['value10'].'</td>
                        <td> '.$row['value11'].' </td>
                        <td> '.$row['value12'].' </td>
                        <td> '. $row['value13'].' </td>
                        <td>
                            <button class="center-block btn btn-acept"><i class="fa fa-check" aria-hidden="true"></i>
                            </button>
                        </td>
                        <td>
                            <button onclick="values('. $row['id']. ')" class="center-block btn btn-editar launch-modal" data-modal-id="modal-edit"><i
                                    class="fa fa-pencil" aria-hidden="true"></i>
                            </button>
                        </td>
                </tr>';
    }
    echo '</tbody>
        </table>
       </div>';
}

添加引号,然后将其转义

<button onclick="values(\''. $row['id']. '\')" class="center-block

添加引号,然后将其转义

<button onclick="values(\''. $row['id']. '\')" class="center-block

错误是javascript,您的javascript代码在哪里?错误是javascript,您的javascript代码在哪里?但是如果使用addEventListener,如何将$row['id']参数传递给javascript函数?使用数据属性将数据放入元素中,并在单击按钮时获取该数据属性。请您用一个例子解释一下好吗?我在jquery中遇到了这个错误。min.js:2 Uncaught TypeError:无法读取Null的属性'addEventListener',不确定当发布的代码不使用jquery时为什么会出现jquery错误?无论如何,元素必须可用才能获取它们,请注意,脚本放在具有给定ID的元素之后,等等。但是如果使用addEventListener,如何将$row['ID']参数传递给javascript函数?使用数据属性将数据放入元素中,并在单击按钮时获取该数据属性。请您用一个例子解释一下好吗?我在jquery中遇到了这个错误。min.js:2 Uncaught TypeError:无法读取Null的属性'addEventListener',不确定当发布的代码不使用jquery时为什么会出现jquery错误?无论如何,元素必须可用才能获取它们,请注意,脚本放在具有给定ID的元素之后,等等。