In ASP.NET project trying to implement JS script work, but somehow it fails. I've got my script in Scripts folder, JQuery import in _ViewImports and button in my View
I've also tried importing JQuery in View itself and wrapping script function into $(document).ready(...)
, but neither helped.
Script functionality
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
JQuery import in _ViewImports
<script src="~/lib/jquery/dist/jquery.js"></script>
Using that functionality
<script src="@Url.Content("~/Scripts/copyToClipboard.js")" type="text/javascript"></script>
<button onclick="copyToClipboard("default str")">Copy</button>
On page button is showing normally, but it don't do anything
_ViewImports file is not the correct place to register JavaScript. Try adding the jquery at the layout or in the partial view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.