作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 laravel 和 ckfinder 构建一个“创建帖子”页面,以允许用户上传特色图像。上传后是否可以在页面上显示图像?我使用了错误的代码,但当我在表单上使用 ckfinder 函数onclick'=>"openPopup()"
时,它无法正常工作。事实上,我需要 ckfinder 的响应来定义图像已上传以及在页面上显示图像的时间!
<input id="url" onclick="openPopup()" name="photo" type="text">
$("#url").on("change keydown keypress keyup mousedown click mouseup",function(){
var photo_url = $("#url").val();
var featured_image = $('#side-feature-img');
featured_image.html('<img class="img-responsive" src="'+photo_url+'">');
});
最佳答案
您可以通过监听 files:choose
和 file:choose:resized
事件来完成此操作。当用户使用“选择”或“选择调整大小”工具栏/上下文菜单选项选择文件时,会触发这些事件。
function openPopup() {
CKFinder.popup( {
// Configure CKFinder's popup size.
width: 800,
height: 500,
// Enable file choose mechanism.
chooseFiles: true,
// Restrict user to choose only from Images resource type.
resourceType: 'Images',
// Add handler for events that are fired when user select's file.
onInit: function( finder ) {
// User selects original image.
finder.on( 'files:choose', function( evt ) {
// Get first file because user might select multiple files
var file = evt.data.files.first();
showUploadedImage( file.getUrl() )
} );
// User selects resized image.
finder.on( 'file:choose:resizedImage', function( evt ) {
showUploadedImage( evt.data.resizedUrl );
} );
}
} );
}
function showUploadedImage( url ) {
// Update field's value
jQuery( '#url' ).val( url );
// Show chosen image
var img = jQuery( '<img>' ).attr( 'src', url );
jQuery( '#side-feature-img' ).html( img );
}
关于jquery - 通过 ckfinder 上传后在页面上显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33605588/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!