jquery

revise deeply nested JSON array in DOM

爱⌒轻易说出口 提交于 2021-01-29 12:21:51
问题 I have an HTML page that contains a stringified JSON object. The object has this structure: { "x":{ "key1":[], "key2":{}, "keyN":{}, "myKey":{ "randomID238492":{ "items":[ { "value":"zzzz" }, { "value":"aaaa" }, { ...} ] } } } } I want to replace this object with one in which the "items" array has been sorted. Here is what I will and won't know about the object: "myKey" and "items" will always be the relevant object keys "myKey" will contain only one random ID, and the "items" key will always

How open my toggle-accordion from another page?

喜夏-厌秋 提交于 2021-01-29 12:21:09
问题 I wrote the toggle-accordion. It works good if links and accordion there are on one page, url links works. But how make open my toggle-accordion to url from another page? https://codepen.io/malinosky/pen/wxKzEo $(function(){ var accordionFaqHead = $('.i-accordionFaq-head'); accordionFaqHead.on('click', function() { $(this).next().slideToggle(); }); function accHash() { var hash = $(this).attr('href'); if (hash) { var accordionItem = $(hash); if (accordionItem.length) { accordionItem.find('.i

Infinite counter with increment at two decimals

[亡魂溺海] 提交于 2021-01-29 12:21:02
问题 Trying to create an infinite counter that starts at 10.41 and increases by 10.41 every second. Have looked at various tutorials but I cannot find one that will account for the increase with a decimal number unit (10.41) every second. This is the code I am using: setTimeout(start, 0); var i = 100; var num = document.getElementById('number'); function start() { setInterval(increase, 100); } function increase() { if (i < 100000) { i++; num.innerText = i; } } 回答1: If I understand correctly, all

overwrite the show method in jquery

大城市里の小女人 提交于 2021-01-29 12:11:44
问题 am editing a web app (not my code) , and has alot of modals show up when some message or notification come so i want to add a sound for that modal the problem that this modal is in all over the app , and alot of jquery .show methods i should track and add that sound $('#ajax_alert').show(); i tried to listen to a change, like changing in css attributes but didn't work $('#ajax_alert').on("change",function(){ //make sound }) how can i overwrite the show method ? i can trigger the sound inside

Javascript regex to match only up to 11 digits, one comma, and 2 digits after it

て烟熏妆下的殇ゞ 提交于 2021-01-29 12:10:18
问题 I have a textbox where I want only allowed up to 11 digits, an optional comma, and two more digits after it. Anything else should not be rendered when the key is pressed into the textbox: $('#txt').keypress(function (e) { var code = e.which; var key = String.fromCharCode(code); // REGEX TO AVOID CHARS & A DOT (.) var pattern = /[a-zA-Z]|\./g; var isMatch = pattern.test(key); if (isMatch) { // DO NOT RENDER CHARS & dot e.preventDefault(); } }); The above code works when an invalid key is

Swiper slider does not swipe slides on mobile devices

徘徊边缘 提交于 2021-01-29 12:08:40
问题 Can not fix some issue, I use swiper slider, everything is fine, nice slider, but there is one oroblem, when I am on desktop page version and swipe slider is ok, but when I turn on mobile emulator without reloading page swiper sliders does not swipe, but when I update the page it is ok slides are swiping, how can I fix it without page reloading please, here is code I use if ($('.swiper-container').length) { let mySwiper = new Swiper('.swiper-container', { loop: false, pagination: { el: '

MultiDatesPicker for jQuery UI is not showing

孤街浪徒 提交于 2021-01-29 11:58:52
问题 I am using MultiDatesPicker for jQuery UI, but the datepicker is not showing. Please help. Here with my code: <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="Multiple-Dates-Picker-for-jQuery-UI-latest/jquery-ui.multidatespicker.css"> <script src="Multiple-Dates-Picker-for-jQuery-UI-latest/jquery-ui.multidatespicker.js"></script> <script> $(document).ready(function(){ $('#mdp

make input tag toggle between edit and readOnly

我的梦境 提交于 2021-01-29 11:57:33
问题 I have a question, how do you toggle input tag from edit to readOnly but without using other buttons. I have here my codepen. If you notice I added an event on a div. This one kinda dumb because when they want to edit they click the input and then the next click will disable it. There's something that I saw somewhere. They implemented this same thing. Any links that I could read? thank you. HTML <div id='wasa'> <input id="date" type="date" value="2018-07-22" > </div> JS const test = document

How to update values in Jquery range slider

若如初见. 提交于 2021-01-29 11:52:00
问题 I'm using jquery range slider. I have an ajax call and I set the slider values in that ajax call. The code is as follows: $.ajax({ type: "POST", url: '/api/get-prices/', data: JSON.stringify(filters), contentType: "application/json", beforeSend: function (xhr, settings) { let csrftoken = getCookie('csrftoken'); if (!csrfSafeMethod(settings.type) && !this.crossDomain) { xhr.setRequestHeader("X-CSRFToken", csrftoken); } }, success: function (response) { let min_price = parseInt(_.min(response[

“$.ajax is not a function”, but only if call is placed inside function

随声附和 提交于 2021-01-29 11:43:16
问题 It's been a while since I've done web programming now, and managed to get myself into some trouble. Probably a trivial thing to solve for someone, but I've searched quite a bit online. All I can find are various way to solve the "$.ajax is not a function" problem by using the correct jQuery source. I've got that one figured out. What I'm wondering about is why does the ajax call work perfectly when not inside a javascript function? As soon as a put it in a function, I get the "$.ajax is not a