Settings
|
Sign in
|
Sign up
Bar
Post
Home
>
Bar HTML5
>
View post
Reply the post
|
View author only
There are currently
2
posts.
【案例】HTML属性中引号的转义
Floor 1
巨大八爪鱼
11/29/15 17:06
单引号:'
双引号:"
例如把alert("'Hello \"World\"!")设置为一个链接的onClick事件:
<a href="#" onClick="alert("'Hello \"World\"!");return false">Click me</a>
弹出的对话框为:
不能直接在onClick事件的双引号里写\",而应该写成"
Floor 2
巨大八爪鱼
11/29/15 17:12
对于PHP,直接使用htmlspecialchars函数就行了。
<?php
$script = 'alert("\'Hello \"World\"!");return false';
$script = htmlspecialchars($script);
?>
<a href="#" onClick="<?=$script?>">Click me</a>
输出内容:
PHP默认没有对单引号进行编码,也没必要。
Content converter:
No conversion
Mainland
Taiwan
Hong Kong
Singapore
Reply the post
Content:
User:
You are currently anonymous.
Captcha:
Unclear? Try another one.