我在一个项目中使用WYMeditor,它工作得很好,很容易使用。我添加了一个自定义按钮,打开包含图像缩略图的模态。单击图像,它被插入到WYMeditor中。问题是,第一张图片点击是伟大的,但如果你试图插入超过1张图片,它"加倍",即第一张图片点击= 1张图片插入,第二次图片点击= 2张图片插入,第三次点击= 3张图片插入,等等。在图像插入之后,我也得到了一个"</span>"
,这根本不需要。我看不出为什么会这样,有什么线索吗。下面是WYM插入的代码。
jQuery('.wymeditor').wymeditor({
html: '<p>Hello, World!</p>',
postInit: function(wym) {
var html = "<li class='wym_tools_newbutton'>"
+ "<a name='NewButton' href='#'"
+ " style='background-image:"
+ " url(includes/js/wymeditor/img/media.png);'"
+ " title='Insert an image' >"
+ "</a></li>";
jQuery(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).append(html);
jQuery(wym._box).find('li.wym_tools_newbutton a').click(function() {
jQuery('#modal').show().css( { 'left': (winW-980)/2+'px', 'top': '100px' } ).load('includes/admin/adminListMedia.php');
jQuery('.imgname').live('change',function(){
var InsertImg = '#'+jQuery(this).attr('id');
wym.insert('<img src="http://127.0.1/admin/includes/uploads/'+jQuery(InsertImg).val()+'" />');
jQuery('#modal').empty().hide();
});
return(false);
});
正如你所看到的,我关闭并清空插入时的模态,我这样做是为了"清除"重复,但它不起作用,这是"模态"代码:
<?php
if ($handle = opendir('../../includes/uploads/thumb/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") { ?>
<div class="MediaImgSelect wym_src">';
<img src="includes/uploads/thumb/<?php echo $file; ?>" width="90px" height="90px"/>';
Size
<select class="imgname" id="<?php echo 'img_'.substr($file,0,-4); ?>">
<option value="Select">Select</option>
<option value="thumb/<?php echo $file; ?>">Thumb</option>
<option value="thumb/<?php echo $file; ?>">Small</option>
<option value="thumb/<?php echo $file; ?>">Large<option>
</select>
</div>
<?php }
}
closedir($handle);
}
?>
实际上我得到了答案使用。bind而不是。live在函数