Прошу помощи!
Здравствуйте! Прошу помощи!
Есть код: <!doctype html> <head> <script src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script> <script> $(document).ready(function(){ var gotosite = $("a#gotosite"); gotosite.click(function(){ if (document.getElementById('txt').value=='yandex') { location.href="https://yandex.ru"; } else if (document.getElementById('txt').value=='google') { location.href="https://google.com"; } else { alert("Whoops, something went wrong..."); } }); }); </script> <center><h2>Search by Project or Product Code</h2></center> <center><h3>If you have Project or Product code, put it in the form below and click enter button.</h3></center> <center><input type="text" value="" name="txt" id="txt"></center> <br> <center><a id="gotosite">[Enter]</a></br></br> <a href="https://kharchenko.tumblr.com" href="text.html" style="color: #000000">[Go Home]</a></br></br> <a href="javascript:history.back();" href="text.html" style="color: #000000">[Go to previous page]</a></center> Работу кода можно посмотреть здесь: https://kharchenko.tumblr.com/search-by-code . При вводе "google" идет редирект на сайт гугла, а при вводе "yandex" идёт редирект на сайт яндекса. Но вот в чём вопрос: мне нужно, что бы редирект на сайт, допустим гугла ишёл в случае, если введенный текст содержит "google". Т.е. редирект на сайт гугла если введено google, agoogle, googlea, aaaaaaagoogleaaaaaa. |
Slandewi,
Поиск подстроки |
Цитата:
Не могли бы Вы переделать мой код?) |
Slandewi,
gotosite.click(function(){ var text = document.getElementById('txt').value; if (text.indexOf('yandex') !== -1) { location.href="https://yandex.ru"; } else if (text.indexOf('google') !== -1) { location.href="https://google.com"; } else { alert("Whoops, something went wrong..."); } }); |
Часовой пояс GMT +3, время: 04:51. |