In Skript unten: ich wie eine wählen Sie die Option Droplist erschaffe,jquery Eingabefeld focusout div
Aber wenn ich focusout
Ereignis auf Text-ID nach meinem ausgewählten Text val Ereignisse verwenden, funktioniert nicht!
Eine alternative Lösung?
focusout Ereignis in Block Kommentar
$(document).ready(function(){
//droplist toggle
$('#text').click(function(){
\t $('.droplist').toggle();
});
// text move to input field
$('.droplist p').click(function(){
\t \t var selected = $(this).text();
\t \t $('#text').val(selected, $('.droplist').hide()); \t \t \t
});
// input field foucsout
/*$('#text').focusout(function(){
\t $('.droplist').hide();
});*/
});
#text{
width:200px;
height:35px;
padding-left:10px;
box-sizing: border-box;
margin-bottom:3px;
}
.droplist{
width:200px;
background-color:#D8D8D8;
border-radius:4px;
padding:5px;
position:absolute;
box-sizing: border-box;
font-family:arial;
font-size:15px;
display:none;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div style="margin:20px;">
\t <input type="text" id="text" autocomplete="off" placeholder="Select Option" />
\t <div class="droplist">
\t \t <p>option one</p>
\t \t <p>option two</p>
\t \t <p>option three</p>
\t \t <p>option four</p>
\t \t <p>option five</p>
\t </div>
</div>
</body>
</html>
Meine erste Frage ist ... Warum? Zuerst sollte das div mit P Elementen eine Liste sein (ul und li), oder noch besser, ein select. Machen Sie das Formular richtig und verwenden Sie jQuery UI, um styleable Dropdowns zu erstellen. – junkfoodjunkie