JavaScript没有';无法使用php echo
我对php javaScript echo有问题。我想为使用echo动态创建的按钮启动一个javaScript函数 当我在没有回声的情况下测试它时,函数的使用是正确的。但当我使用echo创建它时,它不起作用 下面是pages.php中的回声:JavaScript没有';无法使用php echo,javascript,php,ajax,jquery,Javascript,Php,Ajax,Jquery,我对php javaScript echo有问题。我想为使用echo动态创建的按钮启动一个javaScript函数 当我在没有回声的情况下测试它时,函数的使用是正确的。但当我使用echo创建它时,它不起作用 下面是pages.php中的回声: $cont.='<div style="border-bottom: 1px solid #A2DBFF; padding-bottom: 25px; padding-top: 20px; margin-bottom: 10px; margin-le
$cont.='<div style="border-bottom: 1px solid #A2DBFF; padding-bottom: 25px; padding-top: 20px; margin-bottom: 10px; margin-left: 25px;">';
$cont.='<div class="SUBH">
<input type="text" id="txtNEWHEADING" name="txtSubNam" placeholder="The new heading" />
</div>';
$cont.='<div class="PTAG">
<p>
<textarea rows="5" id="disNEWCONT" cols="70" placeholder="add a discription here.." name="txtCont"></textarea>
</p>
</div>';
$cont.='<div class="IMGTAG">
<input type="file" id="imgNewIMAGE" />
<button class="btnSav" type="submit" onclick="SaveContent()" id="btnNEWCONTENT" style="margin-left: 300px;" />save</button>
</div>';
$cont .= '</div>';
$cont.='';
$cont.='
';
$cont.='
';
$cont.='
拯救
';
$cont.='';
javaScript在这里:
$cont .= '
<script type="text/javascript">
$("#btnNEWCONTENT").click(function(){
alert("hi there..");
$.ajax({ url: \'ajax.php\',
data: {action: \'test\'},
type: \'post\',
success: function(data) {
alert(data);
}
});
});
</script>
';
echo $cont;
$cont.='
$(“#btnNEWCONTENT”)。单击(函数(){
警惕(“你好……”);
$.ajax({url:\'ajax.php\',
数据:{操作:\'test\'},
类型:\'post\',
成功:功能(数据){
警报(数据);
}
});
});
';
echo$cont;
请提供帮助。此代码适用于我,在head之间添加了jquery,并将javascript封装到函数中:
<html>
<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
</head>
<body>
<?php
$cont='<div style="border-bottom: 1px solid #A2DBFF; padding-bottom: 25px; padding-top: 20px; margin-bottom: 10px; margin-left: 25px;">';
$cont.='<div class="SUBH">
<input type="text" id="txtNEWHEADING" name="txtSubNam" placeholder="The new heading" />
</div>';
$cont.='<div class="PTAG">
<p>
<textarea rows="5" id="disNEWCONT" cols="70" placeholder="add a discription here.." name="txtCont"></textarea>
</p>
</div>';
$cont.='<div class="IMGTAG">
<input type="file" id="imgNewIMAGE" />
<button class="btnSav" type="submit" onclick="SaveContent()" id="btnNEWCONTENT" style="margin-left: 300px;" />save</button>
</div>';
$cont.='</div>';
$cont.='
<script type="text/javascript">
function SaveContent(){
$("#btnNEWCONTENT").click(function(){
alert("hi there..");
$.ajax({ url: \'ajax.php\',
data: {action: \'test\'},
type: \'post\',
success: function(data) {
alert(data);
}
});
}); }
</script>
';
echo $cont;
?>
</body>
</html>
jQuery库是什么时候加载的?没有理由说两个相同的HTML页面会有不同的工作方式,您可以发布这两个页面吗?PHP只是生成发送到浏览器的输出。在浏览器中查看源代码以查看它输出的内容,并查看是否可以找到它不是您想要的内容的位置。您可能还需要读取HEREDOC字符串。是否可以在浏览器上显示结果输出?