1. 在php端用正则匹配出img标签
2. 用strpos + strsub 函数拼接 οnlοad="resize(this)"
3. 在前端的head标签里面编写resize函数
js硬绑定的好处: 以最快时间响应事件。
2. 用strpos + strsub 函数拼接 οnlοad="resize(this)"
3. 在前端的head标签里面编写resize函数
js硬绑定的好处: 以最快时间响应事件。
//
img硬绑定onload事件, 123宝贝网(www.123baby.net)
if
(preg_match_all(
'@(<img [^>]+>)@i'
, $topic[
'Content'
], $mc) !=
FALSE
&& !
empty
($mc[1][0]))
{
foreach
($mc[1]
as
$item)
{
$pos = strpos($topic[
'Content'
], $item);
if
(
false
!== $pos)
$topic[
'Content'
] = substr($topic[
'Content'
], 0, $pos+5).
' οnlοad="img_resize(this)" '
.substr($topic[
'Content'
], $pos+5);
}
}