我有以下代码,有助于创建附加文件的自定义选项。当我运行代码时,我得到此错误TypeError:$(...)为null。我发生在它自己的代码的第一行。我试图在票证表格上使用它。有人可以告诉我代码中的错误是什么。它在Zendesk门户网站中不起作用。
var frame=$('#upload_frame').html('<iframe></iframe>').find('iframe');
var fileform='<form method="POST" action="/fileuploads?format=js"> Attach log files <input type="file"></form>';
var frameinit=function() {
frame.contents().find('body').children().remove();
frame.contents().find('body').append(fileform);
frame.contents().find('input').change(function(){
frame.contents().find('form').submit();
});
};
frameinit();
$('#SelectFile').click(
function() {
frame.contents().find('input').click();
//Callback to load the result from iframe
frame.load(function() {
//it is just for jsfiddle
var data=frame.contents().find('.pageHeader');
$('body').append($('<div>').html(data));
frameinit();
});
});
答案 0 :(得分:2)
我想你没有包含jQuery库本身。你需要像那样包含它
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>