Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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 innerhtml中的警报按钮_Javascript_Php_Innerhtml_Codeigniter 3 - Fatal编程技术网

Javascript innerhtml中的警报按钮

Javascript innerhtml中的警报按钮,javascript,php,innerhtml,codeigniter-3,Javascript,Php,Innerhtml,Codeigniter 3,我有一个javascript函数在div innerhtml中调用这个结果。点击按钮时如何提醒“提醒功能” $html.='<table class="table table-striped table-bordered table-hover"> <thead> <tr> <th width="5%">#</th>

我有一个javascript函数在div innerhtml中调用这个结果。点击按钮时如何提醒“提醒功能”

$html.='<table class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th width="5%">#</th>
                    <th>Title</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>';
            $c=1;
        foreach($titles AS $item){
            $html.='<tr>
                    <td>'.$c.'</td>
                    <td>'.urldecode($item->title_content).'</td>
                    <td><button type="button" class="btn btn-danger" onclick="alert(\'**Alert Function**\')">Delete</button></td>
                </tr>';
                $c++;
        }
        $html.='</tbody>
         </table>';
        echo $html;
$html.='
#
标题
行动
';
$c=1;
foreach($项目名称){
$html.='
“.$c.”
“.urldecode($item->title\u content)。”
删除
';
$c++;
}
$html.='
';
echo$html;

谢谢

因为这是PHP,您可以直接插入
onClick()
事件,如下所示:

<td><button type="button" id="deleteButton" class="btn btn-danger" onclick="alertFunction()">Delete</button></td>
让我知道这是否解决了您的问题,以及我是否正确理解了您的问题

如果此
onClick()
是用JavaScript本身编写的,则删除该部分并在JavaScript脚本中添加额外的行:

document.getElementById("deleteButton").addEventListener("click", alertFunction);

创建一个单独的函数来处理
onclick
事件。这将有助于在未来,如果你想通过任何论点

<td><button type="button" class="btn btn-danger" onclick="clickButton()">Delete</button></td>

这段代码有什么问题?实际上上面的代码是由javascrip调用的,我使用ajax将值传递给控制器,然后在div中传递innerhtml视图。当它显示在div上时,但是onclick按钮不工作。实际上上面的代码是由javascrip调用的,我使用ajax将值传递给控制器,然后在div中使用innerhtml视图。当它显示在div上时,但onclick按钮不工作。@mohdharlladtfibinamat另外,您可以使用
EventListener()
有助于避免原始文本而不是函数调用。编辑的答案。实际上上面的代码是由javascrip调用的,我使用ajax将值传递给控制器,然后在div中传递innerhtml视图。当它显示在div上时,但onclick按钮不起作用。
<td><button type="button" class="btn btn-danger" onclick="clickButton()">Delete</button></td>
function clickButton(){
 alert('Alert Function')
}