<输入类型="隐藏"功能问题 [英] <input type="hidden" functionality issue

查看:35
本文介绍了<输入类型="隐藏"功能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 javascript 的拆分菜单系统.因为我正在请求信息,所以我使用了输入标签.

Iv'e got a split menu system using javascript. Because im requesting information, im using the input tags.

我不希望复选框、文本框、单选按钮等干扰设计.所以我尝试了隐藏输入类型.保留设计,但如果未选择任何内容,则继续恢复为女性,或列表中的第一个.例如.我选择男性并提交.男性选择进入我的代码.现在,我做其他事情并单击提交,下面的代码在没有我说的情况下恢复为女性.它不会用支票或收音机来做这个,那么为什么它用隐藏"来做这个.

I dont want checkboxes, textboxes, radio butons etc interfering with the design. So i tried the hidden input type. Keeps the design, but keeps reverting back to female, or the first one on the list, if nothing was selected. For example. I select male and submit. Male selection enters my code. Now, i do something else and click submit, and the below code reverts back to female with out me say so. It dosent do thise with check or radio, so why does it do this with "hidden".

另外,如果我不想扰乱功能或设计,我应该使用什么输入类型,或者我还能怎么做.

Also, what input type should i use if i dont want to upset function or design, or how else can i go about this.

<script type="text/javascript">
    $(document).ready(function() {
        $(".dropdown  a").click(function() {
            $(".dropdown ul").toggle();
        });

        });                                
        $(".dropdown ul li a").click(function() {
            var text = $(this).html();
            $(".dropdown a span").html(text);
            $(".dropdown ul").hide();
            $("#result").html("Selected value is: " + getSelectedValue("sample"));
        });

        function getSelectedValue(id) {
            return $("#" + id).find("li a span.value").html();
        }

        $(document).bind('click', function(e) {
            var $clicked = $(e.target);
            if (! $clicked.parents().hasClass("dropdown"))
                $(".dropdown ul").hide();
        });

    });

<form action="" method="get">   
 <div class="sort">
<ul> 
  <li id="sample" class="dropdown">
    <a href="#">Gender |<span>{{ gender }}</span></a>

    <ul><li><a href="#"><input id="radio1" name="Gender" value="Female"/>Female</a>
            <a href="#"><input id="radio2" name="Gender" value="Male"/>Male</a>
            <a href="#"><input id="radio3" name="Gender" value="Both Sexes"/>Both Sexes</a>

    </li></ul>
  </li>
</ul>

推荐答案

您使用这些完全错误.单击 A 标签在这里没有任何改变.为什么你会期望它?

You are using these completely wrong. Clicking the A tags is changing nothing at all here. Why would you expect it to?

您应该使用单选按钮,但要正确应用样式.或者将隐藏字段减少为一个,并使用 Javascript 更改其值.不过,这是一个糟糕的设计,因为用户没有指示他们选择了什么.

You should use the radio button, but apply styles to it properly. Or reduce your hidden fields to just one, and use Javascript to change its value. That's a bad design, though, because the user is given no indication what they have selected.

这篇关于&amp;lt;输入类型=&amp;quot;隐藏&amp;quot;功能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆