ReferenceError:电子未定义
ReferenceError: electron is not defined
本文关键字:未定义 ReferenceError 更新时间:2023-09-26
我在给定的SSCCE代码中得到以下错误:
Error: ReferenceError: electron is not defined
Source File: http://localhost/testingOne.php
Line: 1
而'electron'
是一个字符串。那我为什么会犯这个错误呢。WHile我在这里尝试了被接受的答案,并将electron
和proton
封装在"
中,但这给出了:
Error: SyntaxError: syntax error
Source File: http://localhost/testingOne.php
Line: 1, Column: 12
Source Code:
clickButton(
代码:
<?php
echo '<html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function clickButton(alp, bet) {
alert(alp);
alert(bet);
}
</script>
</head><body>';
$array = array('alpha'=>'electron', 'beta'=>'proton');
echo '<button type="button" onclick="clickButton('. $array['alpha'].','.$array['beta'] .')" >Click Me</button>';
echo '</body></html>';
?>
如果您要查看正在创建的实际HTML的源代码,您会看到:
<button type="button" onclick="clickButton(electron,proton)" >Click Me</button>
您需要在输出值周围添加引号,以将它们转换为Javascript字符串文字:
echo '<button type="button" onclick="clickButton('''. $array['alpha'].''','''.$array['beta'] .''')" >Click Me</button>';
给予:
<button type="button" onclick="clickButton('electron','proton')" >Click Me</button>
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Wordpress中带有JQuery Accordion的未定义匿名函数
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件