无法使用php和js动态创建按钮

时间:2017-12-01 14:27:14

标签: javascript php html5

我尝试构建一个页面,因为客户端通过php js交互作为休闲登录

$hold = ("< button onclick = `
        function myFunction(){
            alert('works!');
        }
        myFunction();
        ` >My balance</button>");

echo hold;

然后我想通过js

将dinamicly发送到html
var Permition = localStorage.getItem("Permition");
$.post('MenuConstructor.php',
{ 
    Permition:Permition
}, 
function(data){
    menu = data;
    //alert(data);
    document.getElementById("div").innerHTML = menu;
}
);

但是对于一些共鸣,警报不起作用你们有什么建议吗? 有时我得到错误未定义有时我得到错误&#34;未终止模板文字&#34;

1 个答案:

答案 0 :(得分:0)

"Unterminated template literal"
:) You need escape illegal character.
<div onclick="alert("123")">
<div onclick="alert(&quot;123&quot;)"> // php htmlspecialchars (maybe) (single ' is &apos;) quot with no "e" at it's end 
$url = 'index.html?a='.urlescape($value);
echo '<a href="'.htmlspecialchars($url).'"></a>'