我认为我的问题对于javascript开发人员来说确实很简单,但是作为后端开发人员,我必须解决一些javascript问题。
我的问题: 我希望使用jquery在单击特定文件时显示下载按钮。
<button type="button" class="btn btn-danger btn-sm pull-right" style="margin:0 3px" onclick="delete_file();"><i class="glyphicon glyphicon-remove"></i> Delete</button>
我有这个javascript:
function download_file() {
var fileId = $($(".contextMenuFile.activeFile")
[0]).attr("data-file")
var url = '/downloadFile/' + fileId
var link = document.createElement("a");
link.download = name;
link.href = url;
link.click(); }
答案 0 :(得分:1)
display:none
show
更改div样式。
// To show button
$("#button_show_starter").click(function() {
$(".button_wrapper").show("slow", function() {
// Animation complete.
});
});
// To hide button if visible when clicking on other elements
$("body").click(function(e) {
const target = $(e.target);
if (!target.is('#button_show_starter') && !target.is('.pull-right')) {
$('.button_wrapper').hide();
}
});
function delete_file() {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div class="button_wrapper" style="display: none">
<button type="button" class="btn btn-danger btn-sm pull-right" style="margin:0 3px" onclick="delete_file();"><i class="glyphicon glyphicon-remove"></i> Delete</button>
</div>
<p id="button_show_starter">SHOW ME THE BUTTON</p>
<div>You can tap here</div>
<div>Or here to hide button if vibisble</div>
</body>