echo"<div class='btn-likes'><input type='button' title='".ucwords($str_like)."' class='".$str_like."' onClick='addLikes(".$tutorial['id'].",".$str_like.")' /></div>";
以上代码的输出:
<input title="Like" class="like" onclick="addLikes(51,like)" type="button">
输出我想要的内容:
<input title="Like" class="like" onclick="addLikes(51,'like')" type="button">
onclick="addLikes(51,'like')"
中缺少撇号
我试过了:
echo"<div class='btn-likes'><input type='button' title='".ucwords($str_like)."' class='".$str_like."'
onClick='addLikes(".$tutorial['id'].",'".$str_like."')' /></div>";
输出如此可见:
<input title="Like" class="like" onclick="addLikes(51," like')'="" type="button">
任何人都可以帮助我?
答案 0 :(得分:2)
您需要转义引号:
echo '<div class="btn-likes"><input type="button"
title="'.ucwords($str_like).'" class="'.$str_like.'"
onClick="addLikes('.$tutorial['id'].',\''.$str_like.'\')" /></div>';
答案 1 :(得分:2)
以下是如何使用\
转义的引号修改代码:
echo '<div class="btn-likes">
<input type="button" title="' . ucwords($str_like) . '" class="' . $str_like . '" onClick="addLikes(' . $tutorial['id'] . ", '" . $str_like . "')\"/>
</div>";