为javascript输出筛选HTML
Filtering HTML for javascript output
我正在使用prettyPhoto API手动打开灯箱,代码如下:
api_images ['images/fullscreen/image1.jpg','images/fullscreen/image2.jpg','images/fullscreen/image3.jpg'];
api_titles = ['Title 1','Title 2','Title 3'];
api_descriptions = ['Description 1','Description 2','Description 3']
$.prettyPhoto.open(api_images,api_titles,api_descriptions);
我面临的问题是,描述值来自Wordpress的所见即所得,代码很容易被随机的html标签、标点符号等破坏
<script type="text/javascript">
$(document).ready(function() {
$('#menu-item-1006').on('click', function(e) {
e.preventDefault();
var images = new Array();
var descriptions = new Array();
var titles = new Array();
<?php
$i = 0;
$images = new WP_Query(array('post_type' => 'clearance', 'showposts' => -1, 'order' => 'menu_order', 'orderby' => 'ASC'));
if ($images->have_posts()) : while ($images->have_posts()) : $images->the_post();
$featured = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
?>
images[<?php echo $i; ?>] = '<?php echo $featured[0]; ?>';
titles[<?php echo $i; ?>] = '<?php the_title(); ?>'
descriptions[<?php echo $i; ?>] = '<?php echo get_the_content(); ?>';
<?php
$i++;
endwhile;
else:
?>
<?php endif; ?>
$.prettyPhoto.open(images, titles, descriptions);
})
});
</script>
如何过滤get_the_content()函数,使其输出w/o错误?谢谢
一个简单的解决方案可以是:
更换
<?php echo get_the_content(); ?>
带有
<?php echo preg_replace('/'<[^'>]+'>/s', '', get_the_content()); ?>
json_encode(get_the_content())有效!
$content = get_the_content();
echo strip_tags($content, '<a><img>');
将只留下CCD_ 1和CCD_。我认为这就是你对画廊的所有需求
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何设置html元素填充的动画
- 使用JQuery通过下拉菜单筛选HTML表值
- 计数HTML表中筛选的结果
- 如何筛选要写入新文档的HTML,删除JavaScript中的某些类和/或ID
- Html和javascript<选择>带有筛选的标签
- 使用javascript单击按钮,根据值筛选html表
- 筛选包含大数据的html表(超过12K行)
- 功能性 HTML 表(排序、筛选、移动和切换列)
- 使用输入文本框搜索和筛选 html 表数据
- JavaScript-正在筛选'<'足够好,可以在显示之前保护HTML
- 根据其他行中的内容筛选HTML表行
- HTML实时筛选表
- 为javascript输出筛选HTML
- 通过HTML SELECT对象筛选Json功能
- 使用html select对筛选表进行ajax刷新
- 带筛选器的HTML选择字段
- 使用javascript从html列表中筛选元素
- jQuery Json筛选并附加到HTML选择器
- HTML中按条件进行角度自定义筛选;不起作用