验证没有表单标签的字段、选择或复选框

发布于 2024-12-26 07:23:31 字数 851 浏览 2 评论 0原文

美好的一天,

我发现了很多与此相关的主题,但是没有正确的答案。

许多主题都以问题结束,为什么你不能添加表单?

我正在开发一个基于 ASP.NET 的项目,我有一个表单标签,一个包含其中所有 html 代码的表单标签。

我无法使用任何 ASP.NET 控件,必须通过前端 (jQuery) 进行验证。

当只有一个表单和一个提交按钮时,一切都很好,然后我可以使用简单的查询验证插件,但当我有多个表单,当然还有多个提交按钮时,它会变得复杂。

例如:

<html>
<head></head>
<body>
<form method="post" action="" id="form123">

<div id="wrapper">

<div id="form1">
<input id="field1 "type="text" />
<input id="submit1" type="submit" value="submit" />
</div>

<div id="form2">
<input id="field2" type="text" />
<input id="submit2" type="submit" value="submit" />
</div>

</div>

<form>
</body>
</html>

有什么建议、想法或真实的例子吗?

也许我可以以某种方式将每个字段和提交按钮放入 div 中,并通过在该 div 中提交来验证它们?

谢谢你!

Good day,

I found a lot of topics about that, but, without a proper answer.

Many of topics ended with question why you just can't add form?

I'm working on a project that based on ASP.NET and I have one form tag, one form tag that contains all the html code inside it.

I can't use any ASP.NET controls and must done validation by front-end (jQuery).

Everything is fine when there is only one form and one submit button, then I can use simple query validation plugin, but it gets complicated when I have more than one form and of course more than one submit button.

For example:

<html>
<head></head>
<body>
<form method="post" action="" id="form123">

<div id="wrapper">

<div id="form1">
<input id="field1 "type="text" />
<input id="submit1" type="submit" value="submit" />
</div>

<div id="form2">
<input id="field2" type="text" />
<input id="submit2" type="submit" value="submit" />
</div>

</div>

<form>
</body>
</html>

Any suggestion, ideas or real example how to do that?

Maybe I can somehow put every field and submit button inside a div and validate them by submit within that div?

Thank you!

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

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

发布评论

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

评论(1

扭转时空 2025-01-02 07:23:31

对需要单独验证的元素使用特定的类或 ID。

所以它最终会看起来像这样:

<form>

    <input id="myFirstField" />

    <button id="myFirstButton">First Button</button>

    <input id="mySecondField" />

    <button id="mySecondButton">Second Button</button>

</form>

然后使用任何你的验证插件你可以做这样的事情:

$('#myFirstButton')click(function(){

     $('#myFirstField').validate("whatever");

});

并做有条件的事情,等等

use specific classes or ids on the elements you need to validate separately.

so it will end up looking something like:

<form>

    <input id="myFirstField" />

    <button id="myFirstButton">First Button</button>

    <input id="mySecondField" />

    <button id="mySecondButton">Second Button</button>

</form>

and then using whatever your validation plugin you can do things like:

$('#myFirstButton')click(function(){

     $('#myFirstField').validate("whatever");

});

and do conditional things, etc etc

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