跟踪在 javascript 中提交了哪个动态锚标记
Track which dynamic anchor tag was submitted in javascript
我对 JavaScript 没有太多经验。
如果用户已经按下了这个动态锚标记,我希望它用不同类型的确认消息提醒他。
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Dataset</th>
</tr>
</thead>
<tbody>
@foreach ($dumpDb as $key => $value)
<tr>
<td scope="row">{{ $value->dataset }}
<span>
<a class="downloadLink" href="{{Route('dump.downloadFile', ['id' => $value->dataset ])}}" onclick="return ConfirmDownload()"> Download </a>
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
<script type="text/javascript">
// dalifyDownloads - how many times a user can download file in 24hours. By default 5 files per day.
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (User has already pressed on this button) {
var x = confirm("Are you sure you want to download this file?");
if (x)
return true;
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}
</script>
您可以使用函数外部的变量进行跟踪:
var pressed = false;
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (!pressed) {
var x = confirm("Are you sure you want to download this file?");
if (x){
pressed = true;
return true;
}
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}
我对 JavaScript 没有太多经验。
如果用户已经按下了这个动态锚标记,我希望它用不同类型的确认消息提醒他。
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Dataset</th>
</tr>
</thead>
<tbody>
@foreach ($dumpDb as $key => $value)
<tr>
<td scope="row">{{ $value->dataset }}
<span>
<a class="downloadLink" href="{{Route('dump.downloadFile', ['id' => $value->dataset ])}}" onclick="return ConfirmDownload()"> Download </a>
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
<script type="text/javascript">
// dalifyDownloads - how many times a user can download file in 24hours. By default 5 files per day.
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (User has already pressed on this button) {
var x = confirm("Are you sure you want to download this file?");
if (x)
return true;
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}
</script>
您可以使用函数外部的变量进行跟踪:
var pressed = false;
function ConfirmDownload() {
var dailyDownloads = {{ Auth::user()->dailyDownloads}};
if (!pressed) {
var x = confirm("Are you sure you want to download this file?");
if (x){
pressed = true;
return true;
}
else
return false;
} else {
// If User has not pressed on this button
var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
if (x)
return true;
else
return false;
}
}