如何在blazor Asp.net内核中调用过滤函数js



如何在blazor服务器端调用过滤函数JavaScript我正在使用带有Asp.net核心的Blazor服务器端,我不知道如何在@code{}中将此脚本调用到我的页面.razor

<script> $(document).ready(function(){ 
$("#myInput").on("keyup", function() { 
var value = $(this).val().toLowerCase(); $("#myTable tr").filter(function(){ 
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) }); }); });
</script>

Index.razor

@page "/"
@inject IJSRuntime JsRuntime
<button class="btn btn-primary" @onclick="Test">Test</button>
@Result
@code
{
private bool Result { get; set; } = false;
private async Task Test()
{
Result = await JsRuntime.InvokeAsync<bool>("Test.testFunc");
}
}

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>BlazorApp3</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
</head>
<body>
<app>Loading...</app>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script>
var Test = new function () {
this.testFunc = function () {
console.log("testFunc");
return true;
};
};
</script>
</body>

您可以查看该源代码以了解更多Blazor的Javascripthttps://github.com/ShadyNagy/Blazor.JavaScriptUtilities

相关内容

  • 没有找到相关文章

最新更新