0
我都嘗試from this answer一個js文件,沒有他們的工作:有道包括在另一
$(function() {
var imported = document.createElement('script');
imported.src = '/assets/admin/receipt_zooming.js';
document.head.appendChild(imported);
$('.rotate-receipt').on('click', rotateImage());
$('.zoom-in').on('click', zoomHandler('+'));
$('.zoom-out').on('click', zoomHandler('-'));
//
OR
$.getScript('/assets/admin/receipt_zooming.js', function()
{
$('.rotate-receipt').on('click', rotateImage());
$('.zoom-in').on('click', zoomHandler('+'));
$('.zoom-out').on('click', zoomHandler('-'));
});
});
receipt_zooming文件:
$(function() {
return function() {
var zoomHandler = function(sign) {
return function() {
var index = $(this).data('button-index');
var image = $('#receipt-image-' + index);
switch (sign) {
case '+':
image.width(image.width() + 100);
break;
case '-':
image.width(image.width() - 100);
}
};
};
var rotateImage = function() {
var angle = 0;
return function() {
var index = $(this).data('button-index');
angle = (angle + 90)%360;
var className = 'rotate' + angle;
$('#receipt-image-'+index).removeClass().addClass(className);
};
};
}
});
我需要在另外幾個文件中包含receipt_zooming.js。請幫忙。
編輯:我可以知道爲什麼有人-1而不是幫助嗎?
'我需要在其他幾個文件中包含receipt_zooming.js什麼意思?您不會將一個js文件包含到另一個js文件中,您將兩個文件都包含在HTML頁面中......或者您從js文件中加載另一個文件以包含在頁面上 –
使用文本編輯器並在頭部添加腳本標記你想要的頁面與src文件的路徑 – madalinivascu
我不能將它包含在html文件中,它是一個rails應用程序 –