当显示div时,如何对齐两个不同形式的两个输入字段?

时间:2014-10-20 07:20:26

标签: html css

我在jsp中有两种形式。

我希望两个表单中的输入字段都居中对齐并且在一行中。

我还隐藏了单击输入字段studentName时显示的div。如果单击输入字段regNo,则需要隐藏div。默认情况下,div需要隐藏

现在,当我在输入字段名称中输入内容时,两个输入字段的对齐方式发生了严重变化

jsp代码

<div id="mycontainer">  
    <form method="get" action="number" id="number">
    <!--    <div id="regNoErrorMsgNumber">Only numbers are allowed</div> -->
            <div style="text-align: center;" >
                    <!-- //TODO: Only number, no spaces, no special symbol and 12 digit check-->                

                             <input  width="20" type="text" data-validation="numbers" id="regNo" name="regNo" size="30" maxLength="50" placeholder="Enter Register Number"> <b>OR</b>       

            </div>

    </form>           

    <form method="post" action="name" id="name">                 
                <input  type="text" id="studentName" name="studentName" size="30" maxLength="50" placeholder="Enter Student Name" > 


            <c:set var="salary" scope="session" value="${param.studentName}"/>

        <div id="dropDown" style="display:none">
            <div id="studentNameError">
                <c:if test="${searchBy.hasError}">
                    <c:out
                        value="There are more than 100 results by this name. We suggest you to filter by College Name and/or Department Name" />
                </c:if>
                <br />
            </div>

            <div>
                <b>Filter students by College :</b> <select id="byCollege" name="byCollege">
                    <c:forEach items="${uniqueCollList}" var="uniqueCollList">
                        <option value="${uniqueCollList}">${uniqueCollList}</option>
                    </c:forEach>
                </select>
            </div>
            <br />

            <div>
                <b>Filter students by Department :</b> <select id="byDept" name="byDept">
                    <c:forEach items="${uniqueDeptList}" var="uniqueDeptList">
                        <option value="${uniqueDeptList}">${uniqueDeptList}</option>
                    </c:forEach>
                </select>
            </div>
            <br />
        </div>          
    </form>                 
</div>

css代码

#mycontainer, h1, h3 {
            text-align:center;
        }
        form{
            display:inline-block;
        }       

JS代码

$('#dropDown').hide();
    $(document).ready(function(){
        $('#inputFields').click(function(event){
            if (document.getElementById('regNo').value !=""){           

                $("#number").submit();

            }else if(document.getElementById('studentName').value !=""){
                $("#name").submit();
            }
        });
    });    
    $(document).ready(function(){
          $('#regNo').click(function(event){              
             $('#studentName').val(''); 
             $('#dropDown').hide();
          });
          $('#studentName').click(function(event){            
             $('#regNo').val(''); 
             $('#dropDown').show();
          });

    });

以下是代码http://jsfiddle.net/7zwvcs4n/

1 个答案:

答案 0 :(得分:2)

添加vertical-align:top;到表格的css

    #mycontainer, h1, h3 {
        text-align:center;
    }
    form{
        vertical-align:top;
        display:inline-block;
        max-width: 49%;
        text-align:left;
    }

我更新了你的小提琴http://jsfiddle.net/7zwvcs4n/2/