问题描述
我有一些JavaScript更新了剃刀页面上的输入标签。当我运行代码时,文本是正确的,并且它在浏览器的输入标签中显示为可见或隐藏,这是我期望的。我希望将以下文本分配给我的剃刀页面字符串currentVisibility上的变量,但每次调试时,它都显示为NULL。我的JavaScript在afterrenderasync函数上运行。如何在全局变量中获取此值,以便可以在if语句中使用它?
JS:
function checkClearerChkBox() {
var element = document.getElementById('txtVisibility');
element.value = $("#clearerdiv").css('visibility');
element.dispatchEvent(new Event('change')); //<--makes Blazor see the change
}
RAZOR:
<input id="txtVisibility" @bind="@currentVisbility" />
<button class="btn btn-primary" @onclick="FireMe">Click Me!</button>
string currentVisbility = "";
protected void FireMe()
{
if (currentVisbility == "visible")
{
Console.Write("Test 2");
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await jsRuntime.InvokeVoidAsync("checkClearerChkBox");}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)