2017-08-03 8 views
7

मेरे पास स्क्रीन पर कुछ तत्व हैं जहां उपयोगकर्ता रिकॉर्ड की खोज कर सकते हैं। टेक्स्ट दर्ज करने के बाद और बटन पर क्लिक करने के बाद उन्हें खोज बटन के बगल में एक संदेश दिखाना चाहिए। मेरा कोड ठीक काम करता है लेकिन मेरा संदेश कूदता है और यह पूरी पंक्ति को प्रभावित करता है। संदेश दिखाने के बाद सभी तत्व नीचे जाते हैं और जब संदेश गायब हो जाता है तो सबकुछ सामान्य रूप से वापस चला जाता है। मैं सोच रहा हूं कि जब स्क्री पर संदेश दिखाता है तो मैं तत्वों को कूदने के लिए कैसे रोक सकता हूं? मैं div तत्वों का उपयोग करता हूं लेकिन वे तालिका पंक्तियों और कोशिकाओं के रूप में प्रदर्शित होते हैं। मैं इसका उपयोग करता हूं क्योंकि यह कोड फॉर्म के अंदर है और इस मामले में तालिका का उपयोग वैध HTML प्रारूप/संरचना नहीं है।संदेश प्रदर्शित होने पर पंक्ति कूदने से रोकें?

$('#searchBtn').on('click', function(){ 
 
\t $('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){ 
 
\t \t \t  $(this).removeClass("error").dequeue(); 
 
\t \t \t }); 
 
});
div.formTbl { 
 
\t display: table; 
 
\t width: 100%; 
 
} 
 
div.frRow { 
 
\t display: table-row; 
 
\t text-align: left; 
 
} 
 
div.frCell { 
 
\t display: table-cell; 
 
\t padding-top: 2px; 
 
\t padding-bottom: 2px; 
 
\t padding-left: 0px; 
 
\t padding-right: 0px; 
 
\t text-align: center; 
 
} 
 
span.info, .success, .warning, .error { 
 
\t border: 1px solid; 
 
\t margin: 5px; 
 
\t padding:5px 10px 5px 40px; 
 
\t background-repeat: no-repeat; 
 
\t background-position: 10px center; 
 
\t border-radius: 3px; 
 
\t display: block; 
 
} 
 
span.error { 
 
\t color: #D8000C; 
 
\t background-color: #FFBABA; 
 
\t background-image: url('../Images/error.png'); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div class="formTbl" style="width:650px;"> 
 
    <div class="frRow"> 
 
    <div class="frCell" style="width:85px;"> 
 
     <select name="studMenu" id="studMenu"> 
 
     <option value="1">Name</option> 
 
     <option value="3">DOB</option> 
 
     <option value="4">Gender</option> 
 
     <option value="5">Nationality</option> 
 
     </select> 
 
    </div> 
 
    <div class="frCell" style="width:175px;"> 
 
     <input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: John, Miller" /> 
 
    </div> 
 
    <div class="frCell" style="width:80px;"> 
 
     <input type="button" name="searchBtn" id="searchBtn" value="Search"/> 
 
    </div> 
 
    <div class="frCell"> 
 
     <span id="searchMsg" style="display:none;"></span> 
 
    </div> 
 
    </div> 
 
</div>

कार्य उदाहरण: यहाँ मेरी कोड के उदाहरण है https://jsfiddle.net/dmilos89/xeLj00kg/

+0

आप [प्रदर्शन] (https://www.html5rocks.com/en/tutorials/forms/constraintvalidation/) फ़ॉर्म त्रुटि (0) – MaxZoom

उत्तर

1

इसका कारण यह है अपने त्रुटि संदेश एक ऊंचाई पंक्ति की प्रारंभिक के बाद का है क्या हो रहा है ऊंचाई, तो जब ऐसा लगता है कि चीजें थोड़ा बदलाव करती हैं। नए त्रुटि संदेश को समायोजित करने के लिए शुरुआत में frCell पर एक निश्चित ऊंचाई देना होगा। एक और फिक्स .error से अतिरिक्त मार्जिन को निकालने के लिए हो सकता है, इसलिए जब त्रुटि संदेश दिखाता है तो आपकी पंक्ति इसके लिए समायोजित करने के लिए स्थानांतरित नहीं होगी।

$('#searchBtn').on('click', function(){ 
 
\t $('#searchMsg').addClass("error").show().text('This field is required.').delay(4000).fadeOut('slow').queue(function(){ 
 
\t \t \t  $(this).removeClass("error").dequeue(); 
 
\t \t \t }); 
 
});
div.formTbl { 
 
\t display: table; 
 
\t width: 100%; 
 
} 
 
div.frRow { 
 
\t display: table-row; 
 
\t text-align: left; 
 
} 
 
div.frCell { 
 
\t display: table-cell; 
 
\t padding-top: 2px; 
 
\t padding-bottom: 2px; 
 
\t padding-left: 0px; 
 
\t padding-right: 0px; 
 
\t text-align: center; 
 
} 
 
span.info, .success, .warning, .error { 
 
\t border: 1px solid; 
 
\t padding:5px 10px 5px 40px; 
 
\t background-repeat: no-repeat; 
 
\t background-position: 10px center; 
 
\t border-radius: 3px; 
 
\t display: block; 
 
} 
 
span.error { 
 
\t color: #D8000C; 
 
\t background-color: #FFBABA; 
 
\t background-image: url('../Images/error.png'); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div class="formTbl" style="width:650px;"> 
 
    <div class="frRow"> 
 
    <div class="frCell" style="width:85px;"> 
 
     <select name="studMenu" id="studMenu"> 
 
     <option value="1">Name</option> 
 
     <option value="3">DOB</option> 
 
     <option value="4">Gender</option> 
 
     <option value="5">Nationality</option> 
 
     </select> 
 
    </div> 
 
    <div class="frCell" style="width:175px;"> 
 
     <input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: John, Miller" /> 
 
    </div> 
 
    <div class="frCell" style="width:80px;"> 
 
     <input type="button" name="searchBtn" id="searchBtn" value="Search"/> 
 
    </div> 
 
    <div class="frCell"> 
 
     <span id="searchMsg" style="display:none;"></span> 
 
    </div> 
 
    </div> 
 
</div>

+0

क्या आप समझा सकते हैं कि स्थिति सापेक्ष और पूर्ण क्यों है? –

+0

@espresso_coffee कोड अद्यतन और स्पष्टीकरण ऊपर जोड़ा गया। – Dij

1

सीएसएस में अपने span.info वर्ग से display: block; संपत्ति निकालने का प्रयास करें।

फिडल: https://jsfiddle.net/ncLsfzv3/

+0

के HTML5 मानक तरीके पर एक नज़र डाल सकते हैं यदि मैं डिस्प्ले हटा देता हूं: ब्लॉक करें एक और समस्या का कारण बन जाएगा। उदाहरण के लिए यदि मेरा टेक्स्ट अवधि चौड़ाई से अधिक लंबा है तो मेरी अवधि बीएक्स दूसरी पंक्ति में पाठ को तोड़ने के बजाय टूट जाएगी। –

1

आप पंक्ति के रूप में ही ऊंचाई में मार्जिन और गद्दी बनाने को दूर कर सकते हैं: https://jsfiddle.net/xeLj00kg/2/

span.error { 
    color: #D8000C; 
    background-color: #FFBABA; 
    background-image: url('../Images/error.png'); 
    padding: 0; 
    margin: 0; 
} 
1

padding: 0px; 
margin: 0; 

span.error { 
padding: 0px; 
margin: 0; 
} 

लिए सीएसएस वर्ग जोड़ने का प्रयास करें।

संबंधित मुद्दे