1
我想通过一个变量从PHP到HTML作为“属性”,以便JavaScript(jQuery)可以访问它。如何将变量从php传递给javascript,作为属性?
$variable = addslashes( this is the text, coming from database, which can contain '' ' ' ' ' or "" " " " "" " or even <br><hr> tags );
HTML:
<img id="clickMe" titleAttr="<?php echo $variable; ?>" />
JS:
$('#clickMe').click(function() {
alert ($(this).attr('titleAttr'));
});
现在火狐说其不好的HTML代码,并alert()
显示文本,直到第一个'信号(其余被切断)
“因为\不是HTML中的转义字符。”这是关键 –