方法ONCLICK -ASP.NET CORE -RAZOR页面

发布于 2025-02-13 09:27:20 字数 616 浏览 2 评论 0原文

我有一个带有< a>标签的按钮,在此标签中,我为onClick定义了一种方法。该事件正在调用脚本。我想将我的标签更改为< select,在此标签中,我们不能使用onclick - 我如何在选择中使用onclick标记并调用该脚本?

在我的项目中,我想要单击标签获取记录ID并获取该ID的值 我想要单击SELECT(黑色区域)获取ID记录红色区域并从表

<a href="#" id="Usernm2" name="id"  
   onclick="getSddIdW(@item.Id)" 
   data-target="#ModalSend" data-toggle="modal" class="AllIcon " 
   data-placement="tooltip" title="">
    <i class="btn bg-primary-bright"></i>
</a>

I have a button with a <a> tag and in this tag I've defined a method for the onclick. That event is calling a script. I want to change my tag to <Select> and in this tag we can't use onclick - how can I use onclick in select tag and call that script?

in my project I want when click the tag get record Id and get value of that Id
i want when i click the select (black area) get Id record Red area and get all record value from table

enter image description here

<a href="#" id="Usernm2" name="id"  
   onclick="getSddIdW(@item.Id)" 
   data-target="#ModalSend" data-toggle="modal" class="AllIcon " 
   data-placement="tooltip" title="">
    <i class="btn bg-primary-bright"></i>
</a>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2025-02-20 09:27:21

以下是在&lt; select&gt;中使用OnClick的演示,您可以参考它。

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

@functions{
    public string GetHello()
    {
        return "Hello";
    }
}


<select id="TypeOfUser" name="typeOfUser" class="active text-normal" 
                                       Onclick="RazorFunction()">
    <option value="2" >CMS Users</option>
    <option value="3">Site Users</option>
</select>

<button> aa</button>

@section Scripts
{
 <script>
    function RazorFunction() {
        $("button").html('@GetHello()');
    }

 </script>
} 

结果:

,但我建议您在&lt; select&gt;

结果:

Below is a demo to use onclick in <Select>, you can refer to it.

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

@functions{
    public string GetHello()
    {
        return "Hello";
    }
}


<select id="TypeOfUser" name="typeOfUser" class="active text-normal" 
                                       Onclick="RazorFunction()">
    <option value="2" >CMS Users</option>
    <option value="3">Site Users</option>
</select>

<button> aa</button>

@section Scripts
{
 <script>
    function RazorFunction() {
        $("button").html('@GetHello()');
    }

 </script>
} 

result:
enter image description here

But I suggest you use onchange in <Select>.

result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文