[英]Including embedded javascript functions from external file
I'm using embedded javascript and defined certain functions within to build up a table: 我使用嵌入式javascript并在其中定义了某些功能来建立表格:
<% function createCollectionTableRow(col) { %>
<tr>
<td>
<a href="/<%= database %>/collections/<%= collections[col][0].name %>"><%= collections[col][0].name %></a></td><td><%= collections[col][0].count %>
</td>
<td>
<button id="<%= collections[col][0].name %>_rename_button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#renameModal">Rename</button>
<script type="text/javascript">
$('#<%= collections[col][0].name %>_rename_button').on('click', function() {
$('#rename_button').on('click', function() {
var newname = $('#rename_input').val();
$('#rename').attr('action', '/collections/<%= collections[col][0].name %>/rename?newname=' + newname);
});
});
</script>
</td>
<td>
<button id="<%= collections[col][0].name %>_copy_button" class="btn btn-sm btn-info" data-toggle="modal" data-target="#copyModal">Copy</button>
<script type="text/javascript">
$('#<%= collections[col][0].name %>_copy_button').on('click', function() {
$('#copy_button').on('click', function() {
var selection = $('#select_collection').val();
var db = $('#select_database').val();
$('#copy').attr('action', '/collections/<%= collections[col][0].name %>/copy?db=' + db + '©to=' + selection);
});
})
</script>
</td>
<td>
<form action="/collections/<%= collections[col][0].name %>?_method=DELETE" method="POST">
<button class="btn btn-sm btn-danger">Delete</button>
</form>
</td>
<td>
<button id="<%= collections[col][0].name %>_truncate_button" class="btn btn-sm btn-warning" data-toggle="modal" data-target="#docTruncateModal">Truncate</button>
<script type="text/javascript">
$('#<%= collections[col][0].name %>_truncate_button').on('click', function() {
$('#doc_truncate').attr('action', '/collections/<%= collections[col][0].name %>/truncate');
$('#full_truncate').attr('action', '/collections/<%= collections[col][0].name %>/full_truncate');
});
</script>
</td>
</tr>
Now I might want to reuse said function across different pages but whenever I try to move it to a seperate file, say 'functions.ejs', and use the following statement at the start of each page <% include functions.ejs %>
I get told there's no such function. 现在我可能希望在不同的页面上重用所述函数,但每当我尝试将其移动到单独的文件时,比如说'functions.ejs',并在每个页面的开头使用以下语句
<% include functions.ejs %>
I被告知没有这样的功能。 What gives? 是什么赋予了?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.