Hello dear jquery people. I'm new in jquery
I have some code:
My index html:
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
- <link rel="stylesheet" type="text/css" href="test.css"/>
- <script type="text/javascript" src="jquery-1.10.1.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
-
- (function ($) {
- //тут превращаем select в input
- var id = "test",
- $id = $('#' + id),
- choices = $id.find('option').map(function (n, e) {
- var $e = $(e);
- return {
- id: $e.val(),
- text: $e.text()
- };
- }),
- width = $id.width(),
- realClass = $id.get(0).className,
- realId = $id.get(0).id,
- $input = $('<input>',{width: width});
- $id.after($input);
- $id.hide();
- $id.find('option').remove();
- //превратили
- $input.select2({
- query: function (query) {
- var data = {}, i;
- data.results = [];
- // подтставим то что искали
- if (query.term !== "") {
- data.results.push({
- id: query.term,
- text: query.term
- });
- }
- // добавим остальное
- for (i = 0; i < choices.length; i++) {
- if (choices[i].text.match(query.term) || choices[i].id.match(query.term)) data.results.push(choices[i]);
- }
- query.callback(data);
- }
- }).on('change',function()
- {
- var value=$input.val();
- $id.empty();
- $id.append($('<option>').val(value))
- $id.val(value).trigger('change');
- }
- );
- })(jQuery);
-
- });
- </script>
- </head>
- <body>
- <select id='test' class="testclass">
- <option value="1">test1</option>
- <option value="2">test2</option>
- <option value="3">test3</option>
- <option value="4">test4</option>
- </select>
- </body>
- </html>
my css:
Why it doesn't work?? Can not understand?