问题描述
在网站上使用带有数据表的以下脚本,似乎每次从 Excel 复制单元格时,它都会被复制为 base64 图像,从而执行 GitHub 中显示的 CoffeeScript。我将如何使其仅在选择 div 时在 imagecapture div 上执行?我现在能做的最好的事情就是不执行,除非它在同一页面上,但我需要将其缩小到 div 元素。
https://gist.github.com/STRd6/5286415
<div id="imagecapture" class="span4 target contain" contenteditable="true" <?php if(!empty($ToolItems[0]->Base64)){ $Base64 = $ToolItems[0]->Base64; echo "style=\"background-image: url('$Base64')\";";}?>></div>
下面我稍微修改了它以使用焦点选择但是当我粘贴它时它不会像焦点包装器不在其中时那样执行帖子
$('#imagecapture').focus(function() {
(function($) {
var defaults;
$.event.fix = (function(originalFix) {
return function(event) {
event = originalFix.apply(this,arguments);
if (event.type.indexOf("copy") === 0 || event.type.indexOf("paste") === 0) {
event.clipboardData = event.originalEvent.clipboardData;
}
return event;
};
})($.event.fix);
defaults = {
callback: $.noop,matchType: /image.*/
};
return ($.fn.pasteImageReader = function(options) {
if (typeof options === "function") {
options = {
callback: options
};
}
options = $.extend({},defaults,options);
return this.each(function() {
var $this,element;
element = this;
$this = $(this);
return $this.bind("paste",function(event) {
var clipboardData,found;
found = false;
clipboardData = event.clipboardData;
return Array.prototype.forEach.call(clipboardData.types,function(type,i) {
var file,reader;
if (found) {
return;
}
if (
type.match(options.matchType) ||
clipboardData.items[i].type.match(options.matchType)
) {
file = clipboardData.items[i].getAsFile();
reader = new FileReader();
reader.onload = function(evt) {
var dataURL = evt.target.result;
/** Add to Database */
var queryString = window.location.search;
var urlParams = new URLSearchParams(queryString);
var ToolID = urlParams.get('ToolID')
console.log(dataURL);
$.ajax({
type: "POST",dataType: "json",url: 'ajax/controller.php',data: {
name: 'UpdateBaseImage',UpdateBaseImage: 'True',dataURL: dataURL,ToolID: ToolID
},success: function(data){
console.log('File Uploaded');
}
});
location.reload();
return options.callback.call(element,{
dataURL: evt.target.result,event: evt,file: file,name: file.name
});
};
reader.readAsDataURL(file);
return (found = true);
}
});
});
});
});
})(jQuery);
});```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)