如何在没有 JavaScript 的情况下让 HTML 页面确定要单击哪个按钮(当您按 Enter 键时)?

发布于 2024-08-02 18:38:21 字数 211 浏览 1 评论 0原文

我有一个 ASP.NET 页面,上面有两个部分...一个用于注册,一个用于登录...每个部分都有一个提交按钮。

当我位于页面的登录部分时,我希望在按下“Enter”键时启用第一个“提交”按钮。在注册部分时,我希望在按下“Enter”键时启用第二个“提交”按钮。

问题:我需要可以访问该页面(即我不允许使用 javascript)

有人有任何想法吗? :) :(

I have an ASP.NET page with two sections on it... one for registration, one for login... each having a submit button.

When i'm in the login part of the page, i want the first 'submit' button to engage when 'Enter' is depressed. When in the registration part, i want the 2nd 'submit' button to engage when 'Enter is depressed.

Problem: I need the page to be accessible (i.e. i'm not allowed to use javascript)

Anyone got any ideas? :) :(

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

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

发布评论

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

评论(4

撩起发的微风 2024-08-09 18:38:21

如果两个提交采用不同的形式(听起来好像在这种情况下应该如此),则没有问题。任何正常的浏览器都会从您所在的表单中获取提交按钮。

If the two submits are in different forms (and it sounds as if they should be in this instance) there is no issue. Any sane browser will take the submit button from the form you are in.

晌融 2024-08-09 18:38:21

将控件包装在面板中,然后将面板的默认按钮属性设置为所需的按钮。

http://msdn.microsoft. com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx

Wrap your controls in panels, then set the default button property of the panel to the desired button.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx

我三岁 2024-08-09 18:38:21

它们的形式相同...:(

好吧,你不能改变这一点吗?除非它们共享字段,否则它们不必采用相同的形式。“登录”和“注册”听起来像是两个不同的函数我

没有纯 HTML 方法来指定默认提交按钮,更不用说在不同情况下

包含 JavaScript 本身并不会使您的页面无法访问。关闭 JavaScript 就没事了。

They're in the same form... :(

Well, can you not change that? Unless they share fields, they shouldn't have to be in the same form. ‘login’ and ‘register’ sound like two different functions to me.

There is no pure-HTML way to specify a default submit button, much less different default buttons in different circumstances.

Including JavaScript does not in itself make your page inaccessible. As long as it still works with JavaScript off you're fine.

瑾兮 2024-08-09 18:38:21

只要这两种形式实际上是独立的形式,这应该会自动发生。换句话说,应该有两个独立的

元素,一个用于登录,一个用于注册。

编辑:

浏览器根据具有焦点的表单确定要“按”哪个提交按钮。如果单个表单中有多个提交按钮(听起来像这里的情况),浏览器将使用它找到的第一个提交按钮进行提交。我知道没有办法绕过这种行为。

您实际上是在问如何使用单个表单执行两个操作之一,这会破坏表单模型:表单旨在对单个 URL 执行操作(GET 或 POST)。我可以想到一种方法来解决这种行为,但它不是特别干净。

建议:

我粗略地画了我正在谈论的内容。您基本上可以在表单顶部添加两个单选按钮,一个用于登录,一个用于注册。在这些字段下面有两个字段集,一个包含登录字段,另一个包含注册字段。该表单有一个提交按钮。

点击查看全尺寸图片 http://img220.imageshack.us/img220/5923/ boardc.th.jpg

没有 Javascript 的用户将选中相应的单选按钮并填写相应的字段集。使用Javascript的用户有更好的体验。如果选中登录单选按钮,则隐藏注册字段集。如果选中注册单选按钮,则隐藏登录字段集。

通过适当的造型,你可以让它看起来很漂亮。您的逻辑必须检查单选按钮字段的值以确定要采取的操作,但这应该不会太难。

考虑到单一形式的限制,这就是我能想到的全部。这可能根本不是一个可行的解决方案,具体取决于您的其他限制,但这就是我所拥有的。祝你好运,如果您对我所讨论的内容有任何疑问,请告诉我!

This should happen automatically, as long as the two forms are actually separate forms. In other words, there should be two separate <form> elements, one for login and one for registration.

Edit:

Browsers determine which submit button to "press" based on the form that has focus. If there are multiple submit buttons in a single form, which sounds like the case here, the browser will submit using the first submit button that it finds. I know of no way to get around that behavior.

You're really asking how to perform one of two actions with a single form, which kind of breaks the form model: a form is designed to perform an action (GET or POST) on a single URL. I can think of one way to work around this behavior, but it is not particularly clean.

Suggestion:

I made a crude drawing of what I'm talking about. You basically add two radio buttons to the top of the form, one for login and one for registration. Underneath those you have two fieldsets, one with fields for login and one with fields for registration. The form has a single submit button.

Click to view full size image http://img220.imageshack.us/img220/5923/boardc.th.jpg

Users without Javascript will check the appropriate radio button and fill in the appropriate set of fields. Users with Javascript have a better experience. If the login radio button is checked, hide the registration fieldset. If the registration radio button is checked, hide the login fieldset.

With proper styling, you can make it look nice. Your logic would have to check the radio button field's value to determine what action to take, but that shouldn't be too hard.

That's all I can come up with, given the single form limitation. This might not be a viable solution at all, depending on your other constraints, but it's all I've got. Good luck, and let me know if you have any questions about what I've discussed!

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