我正在使用线程内的文件下载。我的问题是我无法在href和download属性内分配文件名,因此当我尝试下载文件时,它不显示文件。我尝试用特定的数据替换href,它可以正常工作。
请帮助我分配我进入href并下载attrib的文件的名称。
这是我的JavaScript:
$.each(data, function(key, value)
{
var message = value.message;
var cnt = value.count;
var n = message.includes('.jpg') || message.includes('.png') ||
message.includes('.jpeg')|| message.includes('.pdf') || message.includes('.csv') ||
message.includes('.docx') || message.includes('.xlsx');
message = value.message;
$('#divv').append('<a href="uploads/{{"'+value.message+'"}}"
download="{{"'+value.message+'"}}" style="font-weight: bold;"
class="bsi">' +
'<span class="glyphicon glyphicon-download"></span>'+
" "+value.message+'</a>'+
'<i class="bsi_date">'+value.dateReplied+" "+ value.username+'</i>');
getUserFullName(cnt);
}); //each
答案 0 :(得分:0)
您可以使用此功能
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#?").attr("href", "https://whatyouwant/jquery/");
});
});
</script>
</head>
<body>
<p><a href="https://www.whatyouwant.com" id="?">whatyouwant.com</a></p>
<button>Change href Value</button>
<p>Mouse over the link (or click on it) to see that the value of the href attribute has changed.</p>
</body>
</html>
谢谢