我有一个按钮,它执行JS函数:
<button class="btn-orange btn" onclick="expand(this.closest('.profile'))">JavaScript</button>
还有一个按钮,它执行C#,并根据布尔值切换图标:
<button class="btn-orange btn"
@onclick="@(() =>
{
if (tempBool)
{
tempBool = !tempBool;
}
else
{
tempBool = true;
}
})">
<i class="fa @(tempBool ? "fa-compress" : "fa-expand")" aria-hidden="true"></i>
</button>
我如何组合它们?
我try 了OnClientClick
次,JsRuntime.InvokeVoidAsync("expand(this.closest(.profile))");
次,或者把两者都放在onclick事件中.
如何在按钮点击事件中执行JavaScript函数和C?
我try 执行的JavaScript代码
EventPageExpandable.js:
function expand(card) {
card.classList.toggle('profile--expanded');
// If card is not expanded after toggle, add 'unexpanded' class
if (!card.classList.contains('profile--expanded')) card.classList.toggle('profile--unexpanded');
// Else if card is expanded after toggle and still contains 'unexpanded' class, remove 'unexpanded'
else if (card.classList.contains('profile--expanded') && card.classList.contains('profile--unexpanded')) card.classList.toggle('profile--unexpanded');
}
我是如何try 使用JsRuntime的:
await JsRuntime.InvokeVoidAsync("EventPageExpandable.expand", "this.closest('.profile')");
还是像这样?但两者都不起作用.
await JsRuntime.InvokeVoidAsync("expand", "this.closest('.profile')");```