gpt4 book ai didi

javascript - 如何为 HTML 助手 ASP.NET MVC 编写 Javascript 代码?

转载 作者:行者123 更新时间:2023-11-28 10:10:37 25 4
gpt4 key购买 nike

我有一个像这样的 HTML 帮助文本框:

@Html.TextBox("txt1") <br />

现在我想在此文本框上触发 javascript onchange 事件。是否可以这样做,或者我应该使用 HTML 输入类型。

最佳答案

您可以使用 TextBox Html 帮助器方法的 htmlAttributes 参数指定 html 属性,如下所示:

@Html.TextBox("txt1", null, new { onchange="..." })

参见:InputExtensions.TextBox Method

来自上面的链接:

The htmlAttributes parameter consists of an object that contains name/value pairs. The attributes that are specified in the name/value pairs depend on the HTML element that is being rendered.

关于javascript - 如何为 HTML 助手 ASP.NET MVC 编写 Javascript 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7468695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com