jquery

Using non-standard attributes

旧城冷巷雨未停 提交于 2021-02-05 07:07:30
问题 I am having trouble passing around values without using global variables when I am creating html/jquery applications. Quick example 1) Load a table with a class such as "playersTable" 2) Attach a unique ID such as "25" 3) Click on the table row and spawn a row of buttons that will perform actions based on the parent's class and ID; such as query playersTable WHERE row = 25, etc. The issue is that, as I am developing, I need to tie more and more values to the parent element (or any element

Redirect to new page after receiving data from Javascript

丶灬走出姿态 提交于 2021-02-05 07:06:50
问题 I'm trying to pass a Javascript array to my Django views. This works, but I would like to manipulate that data and display it in a separate url. So I have a products page, where you select items. When the form is submitted, this javascript is called, and I want it to redirect to a cart page: $("#getArr").submit(function(){ var data = {'ab[]' : chosen}; $.post('cart/', data, function(response){ if(response == 'success'){ window.location.href="cart/" // references my views } else{ alert('Error!

JQuery - Disable scroll wheel until animation is completed

北城余情 提交于 2021-02-05 07:06:37
问题 I am trying to disable mousewheel on mousewheel event and only enable it after the action is completed. $(window).on('DOMMouseScroll mousewheel', function (event) { //disable mousewhell until the following animation is complete $('.box').animate({ margin: div_offset+'px 0 0 0' }, 500); //enable mousewhell return false; }); I would also like the code to ignore every scroll after the first one, until the animation is complete. In this particular case, I want the animation to complete only once,

How can I add a comma after each 3 digits?

笑着哭i 提交于 2021-02-05 06:57:07
问题 This is simplified of my code: $("#annual_sales").on('keyup', function () { $(this).val( $(this).val().replace(/(\d{3})/g, "$1,") ); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="annual_sales" type="text" /> I'm trying to add a comma after every 3 digits. The patterns works well here , but as you can see (in the code snippet above) it doesn't work in the JS. Any idea what's wrong? 回答1: In your current pattern (\d{3}) you add a comma

validation at least one checkbox (multiple group of checkboxes)

▼魔方 西西 提交于 2021-02-05 06:53:45
问题 I know this've been answered in here But my html looks like below : <div > <label> <input type="checkbox" name="service_area[]" value="colorado">colorado</label> <label> <input type="checkbox" name="service_area[]" value="michigan">michigan</label> </div> <div > <label> <input type="checkbox" name="fav[]" value="skiing">skiing</label> <label> <input type="checkbox" name="fav[]" value="volley">volley</label> </div> Objectives : name must have array, in here : service_area[] must show only one

Get the size of a document when window resize

左心房为你撑大大i 提交于 2021-02-05 06:51:28
问题 I can find the size of window, when i resize my window.like this <script type="text/javascript"> jQuery(window).resize(function () { var width = jQuery(window).width(); var height = jQuery(window).height(); console.log(width); console.log(height); }) </script> Now i want to get the document size when i resize the window. How can i get the size every time when resize the window. 回答1: $(window).width(); // returns width of browser viewport $(document).width(); // returns width of HTML document

When all AJAX requests complete

左心房为你撑大大i 提交于 2021-02-05 06:50:51
问题 I have an ajax request that grabs some data and then splits it up into an array. The array length is variable. var ajax1 = $.ajax({ url: 'myurl.php', type: "GET", dataType: "jsonp", success: function (data) { //create an array } }); Once I have the array, I want to loop through it and in each iteration run another AJAX request. I put it inside a $.when to make sure the initial ajax request was complete: $.when(ajax1).done( function() { for (i = 0; i < array.length; ++i) { $.ajax({ url:

google charts timeline - get text on row mouse click

风流意气都作罢 提交于 2021-02-05 06:43:42
问题 i want to take out 'text value' on mouse click on anywhere on the row/svg image ,for i.e. in the below image if i click anywhere on 2nd blue highlighted row, then i should be able to get the text 'Adams' as alert. I tried to iterate thru svg elements but svg elements are created horizontally rather then vertically 回答1: you can use the 'select' event, to determine the value selected when the 'select' event fires, check chart.getSelection() google.visualization.events.addListener(chart, 'select

How to disable redirecting when clicking on a button?

老子叫甜甜 提交于 2021-02-05 06:41:06
问题 I use Codeigniter and Bootstrap. I have a button: <a class="btn btn-success" id="btnid" href="http://site/controllerName/parameter">Text</a> If I click to the button its call a controller with one parameter then the controller redirects to a site. My question is that is there a way to call the controller with a parameter but skipping the redirection? 回答1: Try following $(document).ready(function(){ // Add your event handlers inside ready block $("#btnid").click(function(event) { // button

How to intercept a submit button click?

橙三吉。 提交于 2021-02-05 06:39:05
问题 I have a form and a submit button. I want to do a quick check on some of the fields (if one isn't filled in, then to blank some of the others). I would rather not change the HTML for the button, I would like to just to do this in jQuery and not add any "onclick" attributes to the button. HTML: <input class="cssButton button_in_cart" type="submit" value="Add to Bag" style="width: 80px;"> jQuery (attempted): $("input.button_in_cart").mousedown(function () { alert("clicked"); }); This doesn't