Помогите с одним скриптом
Дело в том, что с жава сриптом я не силен, все собираюсь начать изучать, но вот тут у меня небольшая проблема...вот сайт на нем вверху форма поиска и покупки билетов. Так вот хочу, что бы поле "обратный рейс" по умолчанию был отключен, а когда жмешь "хочу обратно" оно активировалось...сейчас по умолчанию все наоборот....
Подключено всего 4 скрипта <script src="http://nano.aviasales.ru/assets/autocomplete_places_ru.js?1.85.0" type="text/javascript"></script> <script> //<![CDATA[ var LOCALE = "ru"; //]]> </script> <script src="http://yandex.st/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="http://nano.aviasales.ru/assets/nano_ui/partners/classic_search_form_ru-2b45bd63de343458c02714e0b887b537.js" type="text/javascript"></script> Думаю это либо первый либо последний. Буду благодарен любой помощи. |
ireznik,
Скрипты обфусцированы - занчит работа платная -> раздел работа - хотя может и будут альтруисты - но вряд ли - разбирать скрипты - чтобы помочь |
Там же пустяк просто действие поменять....
|
ireznik,
Ну распаковывать -кто будет ?Они оба ужаты и свернуты Распакуйте выложите на страницу - мну поправит |
ок щас гляну как это делается и чуть поззже выложу
|
Попробуйте поместить скрипт (без инпутов) в самый конец страницы, не факт, что поможет, но всё же
<input type="checkbox" id="aviasales_one_way_checkbox"> <input id="search_params_attributes_return_date"> <script> var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); ch.onclick = function () { if (this.checked == true) { inp.removeAttribute('disabled'); } else { inp.setAttribute('disabled', 'disabled'); } } </script> |
bes, у инпута id=aviasales_one_way_checkbox
Но не айс чекнутый инпут без выбора и наоборот Ксать Вариант пост #6 - не фунциклит |
Цитата:
переопределил только обработчик клика на чекбоксе, думаю других функций по клику на него не возложено, если переопределение будет (последним), то всё должно получиться Цитата:
|
так же...
|
попробуй заменить onclick на onchange
|
вот так примерно должно выглядеть
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Поиск дешевых авиабилетов</title> <link href="style_poisk.css" media="screen" rel="stylesheet" type="text/css" /> <script src="http://nano.aviasales.ru/assets/autocomplete_places_ru.js?1.85.0" type="text/javascript"></script> <script> //<![CDATA[ var LOCALE = "ru"; //]]> </script> <script src="http://yandex.st/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="http://nano.aviasales.ru/assets/nano_ui/partners/classic_search_form_ru-2b45bd63de343458c02714e0b887b537.js" type="text/javascript"></script> </head> <body> <div id="aviasales_page-wrapper"> <form accept-charset="UTF-8" action="http://nano.aviasales.ru/searches/new" data-uniform="" data-validator="true" data-widget="nano_search_form" id="aviasales_new_search" method="get" target="_blank"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div> <div id="aviasales_form_contents"> <input id="11468" name="marker" type="hidden" value="inline-form-test-marker"> <input id="with_request" name="with_request" type="hidden" value="true" /> <input id="currency" name="currency" type="hidden" /> <div class="aviasales_form_line_wrapper"> <div class="aviasales_form_input_unit aviasales_origin"> <label for="search_params_attributes_origin_name"></label> <input data-clearable="require" data-validate="require" data-widget="places_autocomplete" id="search_params_attributes_origin_name" name="origin" type="text" onfocus="if(this.value=='Город вылета') this.value='';" onblur="if(this.value=='') this.value='Город вылета';" value="Город вылета" /> <input id="origin_iata" name="origin_iata" type="hidden" /> </div> <div id="aviasales_change_places"> <div id="aviasales_change_places_bg" class="trigger" data-method="swap_places" data-swaper-to="destination,destination_iata" data-swaper-from="origin,origin_iata" data-widget="swaper"></div> </div> <div class="aviasales_form_input_unit aviasales_destination"> <label for="search_params_attributes_destination_name"></label> <input data-clearable="require" data-validate="require" data-widget="places_autocomplete" id="search_params_attributes_destination_name" name="destination" type="text" onfocus="if(this.value=='Город прилета') this.value='';" onblur="if(this.value=='') this.value='Город прилета';" value="Город прилета" /> <input id="destination_iata" name="destination_iata" type="hidden" /> </div> </div> <div class="aviasales_form_line_wrapper"> <div class="aviasales_form_input_unit aviasales_direct"> <label for="search_params_attributes_depart_date"></label> <input data-datepicker_layout_class="small_calendar" data-datepicker_number_of_months="2" data-validate="date require" data-widget="datepicker" id="search_params_attributes_depart_date" type="text" onfocus="if(this.value=='Дата вылета') this.value='';" onblur="if(this.value=='') this.value='Дата вылета';" value="Дата вылета" style="margin-top: 18px;"/> <div class="aviasales_range"> <label for="aviasales_not_strict_dates_checkbox">± 3 дня</label> <input id="aviasales_not_strict_dates_checkbox" name="range" type="checkbox" value="1" /> </div> </div> <div class="aviasales_form_input_unit aviasales_return"> <div class="aviasales_is-direct"> <label for="aviasales_one_way_checkbox">Хочу обратно</label> <input id="aviasales_one_way_checkbox" name="oneway" type="checkbox" value="1" data-widget-disable="#search_params_attributes_return_date" /> </div> <div> <input data-datepicker_layout_class="small_calendar" data-datepicker_number_of_months="2" data-validate="date" data-widget="datepicker" id="search_params_attributes_return_date" type="text" onfocus="if(this.value=='Обратный рейс') this.value='';" onblur="if(this.value=='') this.value='Обратный рейс';" value="Обратный рейс" /> </div> </div> </div> <div class="aviasales_form_line_wrapper aviasales_count_params"> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="adults" class="aviasales_adults_label" title="Взрослый (> 12)"> <div class="aviasales_passenger_ico">Взрослый</div> </label> <select id="search_params_attributes_adults" name="adults"><option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option></select> </div> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="children" class="aviasales_children_label" title="Ребенок (< 12)" > <div class="aviasales_passenger_ico" style="margin-left:12px">Ребенок</div> </label> <select id="search_params_attributes_children" name="children"><option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option></select> </div> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="infants" class="aviasales_infants_label" title="Младенец (< 2)" > <div class="aviasales_passenger_ico">Младенец</div> </label> <select id="search_params_attributes_infants" name="infants"><option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option></select> </div> <div class="aviasales_form_input_unit aviasales_long_labeled_select"> <p style="position:absolute;right:90px;color:#fff;margin:5px 0;font-weight:bold;font-size: 12px;">Класс</p> <select id="search_params_attributes_trip_class" name="trip_class"><option value="0">Эконом</option> <option value="1">Бизнес</option> <option value="2">Первый</option></select> </div> </div> <div class="input_wrapper submit"> <input class="test" id="search_submit" name="commit" type="submit" value="Найти" /> </div> </div> </div> </form> <script> var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); ch.onchange = function () { if (this.checked == true) { inp.removeAttribute('disabled'); } else { inp.setAttribute('disabled', 'disabled'); } } </script> </body> </html> |
так же((((
|
ну тогда могу ещё предложить только попробовать заключить весь код того скрипта в
window.onload = function (){ //здесь тот код } |
вот так ещё попробуйте (понажимайте несколько раз на чекбокс)
<input type="checkbox" id="aviasales_one_way_checkbox"> <input id="search_params_attributes_return_date"> <script> var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); document.body.onclick = function (e) { e = e || event; var target = e.target || e.srcElement; if (target.id == 'aviasales_one_way_checkbox') { if (target.checked == true) { inp.removeAttribute('disabled'); } else { inp.setAttribute('disabled', 'disabled'); } } } </script> |
<script> window.onload = function (){ var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); ch.onchange = function () { if (this.checked == true) { inp.removeAttribute('disabled'); } else { inp.setAttribute('disabled', 'disabled'); } } } </script> вот так работает...сейчас только с цсс поиграюсь чуток..просто когда неактив оно белое, а когда актив оно серое))спасибо большое) |
сейчас попробую вариант выше..а инпуты добавлять?
|
последний не рабботает..спасибо за предыдущий)
|
window.onload = function (){ var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); ch.onchange = function () { if (this.checked == true) { inp.removeAttribute('disabled'); } else { inp.setAttribute('disabled', 'disabled'); } } } если вот строчку inp.setAttribute('disabled', 'disabled'); убрать ничего не будет хочу переделать что бы если нет галочки применялся стиль дисаблед если есть ничего не происходило |
Последний так-то тоже должен работать
<input type="checkbox" id="aviasales_one_way_checkbox"> <input id="search_params_attributes_return_date"> <script> window.onload = function () { var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; document.body.onclick = function (e) { e = e || event; var target = e.target || e.srcElement; if (target.id == 'aviasales_one_way_checkbox') { if (target.checked == true) { inp.removeAttribute('disabled'); inp.style.background = 'lightgray'; } else { inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; } } } } </script> Цитата:
можно также попробовать просто задать disabled в самом инпуте |
это с импутами в конец надо?
|
вот так должно получиться
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Поиск дешевых авиабилетов</title> <link href="style_poisk.css" media="screen" rel="stylesheet" type="text/css" /> <script src="http://nano.aviasales.ru/assets/autocomplete_places_ru.js?1.85.0" type="text/javascript"></script> <script> //<![CDATA[ var LOCALE = "ru"; //]]> </script> <script src="http://yandex.st/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script src="http://nano.aviasales.ru/assets/nano_ui/partners/classic_search_form_ru-2b45bd63de343458c02714e0b887b537.js" type="text/javascript"></script> </head> <body> <div id="aviasales_page-wrapper"> <form accept-charset="UTF-8" action="http://nano.aviasales.ru/searches/new" data-uniform="" data-validator="true" data-widget="nano_search_form" id="aviasales_new_search" method="get" target="_blank"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div> <div id="aviasales_form_contents"> <input id="11468" name="marker" type="hidden" value="inline-form-test-marker"> <input id="with_request" name="with_request" type="hidden" value="true" /> <input id="currency" name="currency" type="hidden" /> <div class="aviasales_form_line_wrapper"> <div class="aviasales_form_input_unit aviasales_origin"> <label for="search_params_attributes_origin_name"></label> <input data-clearable="require" data-validate="require" data-widget="places_autocomplete" id="search_params_attributes_origin_name" name="origin" type="text" onfocus="if(this.value=='Город вылета') this.value='';" onblur="if(this.value=='') this.value='Город вылета';" value="Город вылета" /> <input id="origin_iata" name="origin_iata" type="hidden" /> </div> <div id="aviasales_change_places"> <div id="aviasales_change_places_bg" class="trigger" data-method="swap_places" data-swaper-to="destination,destination_iata" data-swaper-from="origin,origin_iata" data-widget="swaper"></div> </div> <div class="aviasales_form_input_unit aviasales_destination"> <label for="search_params_attributes_destination_name"></label> <input data-clearable="require" data-validate="require" data-widget="places_autocomplete" id="search_params_attributes_destination_name" name="destination" type="text" onfocus="if(this.value=='Город прилета') this.value='';" onblur="if(this.value=='') this.value='Город прилета';" value="Город прилета" /> <input id="destination_iata" name="destination_iata" type="hidden" /> </div> </div> <div class="aviasales_form_line_wrapper"> <div class="aviasales_form_input_unit aviasales_direct"> <label for="search_params_attributes_depart_date"></label> <input data-datepicker_layout_class="small_calendar" data-datepicker_number_of_months="2" data-validate="date require" data-widget="datepicker" id="search_params_attributes_depart_date" type="text" onfocus="if(this.value=='Дата вылета') this.value='';" onblur="if(this.value=='') this.value='Дата вылета';" value="Дата вылета" style="margin-top: 18px;"/> <div class="aviasales_range"> <label for="aviasales_not_strict_dates_checkbox">± 3 дня</label> <input id="aviasales_not_strict_dates_checkbox" name="range" type="checkbox" value="1" /> </div> </div> <div class="aviasales_form_input_unit aviasales_return"> <div class="aviasales_is-direct"> <label for="aviasales_one_way_checkbox">Хочу обратно</label> <input id="aviasales_one_way_checkbox" name="oneway" type="checkbox" value="1" data-widget-disable="#search_params_attributes_return_date" /> </div> <div> <input data-datepicker_layout_class="small_calendar" data-datepicker_number_of_months="2" data-validate="date" data-widget="datepicker" id="search_params_attributes_return_date" type="text" onfocus="if(this.value=='Обратный рейс') this.value='';" onblur="if(this.value=='') this.value='Обратный рейс';" value="Обратный рейс" /> </div> </div> </div> <div class="aviasales_form_line_wrapper aviasales_count_params"> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="adults" class="aviasales_adults_label" title="Взрослый (> 12)"> <div class="aviasales_passenger_ico">Взрослый</div> </label> <select id="search_params_attributes_adults" name="adults"><option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option></select> </div> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="children" class="aviasales_children_label" title="Ребенок (< 12)" > <div class="aviasales_passenger_ico" style="margin-left:12px">Ребенок</div> </label> <select id="search_params_attributes_children" name="children"><option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option></select> </div> <div class="aviasales_form_input_unit aviasales_short_labeled_select"> <label for="infants" class="aviasales_infants_label" title="Младенец (< 2)" > <div class="aviasales_passenger_ico">Младенец</div> </label> <select id="search_params_attributes_infants" name="infants"><option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option></select> </div> <div class="aviasales_form_input_unit aviasales_long_labeled_select"> <p style="position:absolute;right:90px;color:#fff;margin:5px 0;font-weight:bold;font-size: 12px;">Класс</p> <select id="search_params_attributes_trip_class" name="trip_class"><option value="0">Эконом</option> <option value="1">Бизнес</option> <option value="2">Первый</option></select> </div> </div> <div class="input_wrapper submit"> <input class="test" id="search_submit" name="commit" type="submit" value="Найти" /> </div> </div> </div> </form> <script> window.onload = function () { var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; document.body.onclick = function (e) { e = e || event; var target = e.target || e.srcElement; if (target.id == 'aviasales_one_way_checkbox') { if (target.checked == true) { inp.removeAttribute('disabled'); inp.style.background = 'lightgray'; } else { inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; } } } } </script> </body> </html> |
хех к сожалению все так же и когда стоит галочка в строке ничего все ранво нельзя менять...сори если вас достал с этой формой, просто хочется сделать красиво) с цсс разобрался, а вот жс не идет..
|
первый вариант тоже не работает?
|
<script> window.onload = function () { var inp = document.getElementById('search_params_attributes_return_date'); var ch = document.getElementById('aviasales_one_way_checkbox'); inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; document.body.onclick = function (e) { e = e || event; var target = e.target || e.srcElement; if (target.id == 'aviasales_one_way_checkbox') { if (target.checked == true) { inp.removeAttribute('disabled'); inp.style.background = 'lightgray'; } else { inp.setAttribute('disabled', 'disabled'); inp.style.background = 'white'; } } } } </script> если вы за это, то оно так же...работал ваш самый первый варинат в том, что вы потом сказали обернуть...и все больше пока ничего не работало...но там проблема с стилями стили пробовал перезадавать несовсем то выходило..хотлось бы что бы если галки нет применялся стиль дисаблед, а если есть то все как обычно....прсото если не трудно покаите код и скажите куда вы стили прописываете, а я буду химичить) |
да кст в этом коде импуты я не ставил или их надо было куда то дописать? ну что перед скриптом?
|
ну раз первый скрипт рабочий, его и используйте, как поменять background у инпутов я показал во втором варианте
PS: пациент оказался лечимым по фото |
:) bes,
сасем Замучили , ireznik, попробуйте в конец страницы <style type="text/css"> div.disabled #search_params_attributes_return_date{ background: #D3D3D3!important; } </style> <script> window.onload = function () { setTimeout(function(){// var a=$("#search_params_attributes_return_date"); a.attr("disabled","disabled"); a.parent().addClass("disabled") },200); $("#aviasales_one_way_checkbox").change(function(){ setTimeout(function(){ if($("#aviasales_one_way_checkbox:checked").length){ var a=$("#search_params_attributes_return_date"); a.removeAttr("disabled"); a.parent().removeClass("disabled") } },20); setTimeout(function(){ if($("#aviasales_one_way_checkbox:not(:checked)").length){ var a=$("#search_params_attributes_return_date"); a.attr("disabled","disabled"); a.parent().addClass("disabled") } },20); }); } </script> |
Deff, с $(document).ready можно и не в конец (хотя когда добавили window.onload необходимость в этом также отпала)
|
bes,
У мну в Опере window.onload в jQuery для данного сайта виснет - не стал даж боротся, Чуть поправил в связи с замечанием bes, |
вы(именно с маленькой буквы) долбоёбы рамсы не попутали случайно взломщики? человек защитил свою работу-хочет этот скрипт -пусть связываться с Разработчиком его и оплачивает его или чего там разработчик захочет
|
Deff, там как раз ready в тему было (я лишь имел в виду, что местоположение самого скрипта на странице перестало быть важным), так как ready может быть несколько на странице в отличие от window.onload и они не ждут загрузки картинок
Цитата:
PS: Цитата:
|
Цитата:
|
dmitriymar,
Кто Вам дал Право критиковать налево и направо ?, будь Вы хоть чуточку вежливей, может к Вам и прислушались бы - Тут достаточно взрослые люди принимают решения сами по интересу и востребованности! Опять холивар в теме |
Цитата:
UPD: может он его защитил, чтобы скрыть своё говнокодство |
Цитата:
а говнокодерство-дак ты говнокодер, быдлокодер чистой воды-так что не пизди на других и не пиздим будешь |
dmitriymar,
Вы - чисто провоцирует отвержение любых Ваших доводов - смысл в ваших спичах в темах сводицо - чо я вот такой крутой -а Вы все Цитата:
|
Цитата:
имхо, нет смысла защищать то, что по умолчанию будет всё равно не защищено |
Цитата:
|
Цитата:
Цитата:
Цитата:
я ж написал Цитата:
|
да уж , как говориться -не спорь с долбоёбом. ты-долбоёб
|
Часовой пояс GMT +3, время: 06:31. |