jquery -> js
Добрый вечер, как переписать данный код с jquery на чистый js?
1. $('input[name=options]:checked', '#form').val(); 2. $('#form input').on('change', function() { let Button = $('input[name=options]:checked', '#form').val(); }); 3. $(document).ready(function() { $("#name_button").bind("change input", function() { let getInput = $("#name_button").val(); console.log(getInput); }); }); 4. let getURLmessage = [ "test", "test1", "test2", "test3" ] $(function() { $("#name_button").autocomplete({ source: getURLmessage }); }); |
|
Цитата:
$('input[name=options]:checked, #form').val(); |
Цитата:
<form id='form'> <input type='checkbox' name='options' value='test' checked /> </form> <script type='text/javascript'> var o=document.querySelector('#form input[name=options]:checked'); var val=(o)? o.value: ''; alert(val) </script> |
Цитата:
$('#form input[name=options]:checked').val(); |
3.
document.addEventListener('DOMContentLoaded', function() { const listener = function() { console.log(this.value || ''); }; const node = document.getElementById('name_button'); if (!node) throw new Error('Element not found'); ['change', 'input'].forEach(function(event) { node.addEventListener(event, listener); }); }); |
Спасибо большое!
|
а 2? как будет
|
SpaceAlarm, соберите его самостоятельно из 1 и 3.
|
Цитата:
Вот так должно быть https://jsfiddle.net/qLaaa0dd/ |
Часовой пояс GMT +3, время: 02:31. |