我有那个代码:
<a href="#" onclick="$('#two').html('<img src=\'http://willstern.com/web/wp-content/uploads/2011/06/jquerylogo2.png\' />');return false;">Add an Img</a>
我不知道如何把它放在这里echo ' code ' ;
这会起作用(已测试)
<?php
echo "<a href=\"#\" onclick=\"$('#two').html('<img src=\'http://willstern.com/web/wp-content/uploads/2011/06/jquerylogo2.png\' />');return false;\">Add an Img</a>";
?>
要在 php 中转义单引号或双引号,请在前面添加反斜杠\'
\"
请参阅文档。 http://www.php.net/manual/en/language.types.string.php
啊,是的,jQuery 也是如此请参阅文档。 http://api.jquery.com/Types/#Quoting
当您使用 jQuery 时,我建议您将 JS 与 HTML 分开一点,您可以编写与此相同的代码。
<a href="#" class="add_an_image">Add an Image</a>
<script>
$('.add_an_image').click(function(){
$('#two').html('<img src="http://willstern.com/web/wp-content/uploads/2011/06/jquerylogo2.png" />');
return false;
});
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)