0

强制 jQuery 检测 post-content 类中的元素是否是图像然后在页面中显示该图像的最佳方法是什么。我已经用 BBCode 做过很多次了,但想让用户更容易。只需允许他们粘贴链接,系统就会从那里开始。

            $comments = $posts_row['post_content'];

            $m = preg_match_all( "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", $comment, $match);

            if ($m) {
                 $links = $match[0];
                 foreach($links as $link) {
                 $extension = strtolower(trim(@end(explode(".",$link))));
                 switch($extension) {
                 case 'gif':
                 case 'png':
                 case 'jpg':
                 case 'jpeg':
                   $comment = str_replace($link, '<img src="'.$link.'">', $comment);       
                 break;
                 default:
                 $comment = str_replace($link, '<a rel="nofollow" href="'.$link.'">'.$link.'</a>', $comment);
                 break;
                 }
              }
            }
4

1 回答 1

0

试试这个:

$('.post-content').find('img').show()
于 2012-08-04T00:48:41.877 回答