javascript-framework

Sorting array using Javascript function - Understanding

南楼画角 提交于 2019-12-02 12:56:04
问题 I decided to get shuffled values from array. for that i used this function, i got it from net, it works fine. But i don't know, how it's works... any one can help me to understand this? my code is : function rand(ar){ return 0.5-Math.random(); } var ar = [5,10,15,20,25] ar.sort(rand); console.log(ar) I am using this function for getting new shuffled array values from the declared one. 回答1: This code is using the supplied rand function as the comparison operator for the Array.Sort method (http

How exactly does the AngularJS Digest Loop work?

半世苍凉 提交于 2019-12-02 11:30:51
I am new to AngularJS and I am studying it on a tutorial. I have some doubt about the concept related to the Digest Loop provided by Angular. My application is composed by these 2 files: 1) index.html : <!DOCTYPE html> <html lang="en-us" ng-app="myApp"> <head> <title>Learn and Understand AngularJS</title> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <meta charset="UTF-8"> <!-- load bootstrap and fontawesome via CDN --> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> <style> html, body, input, select, textarea { font-size: 1.05em; } <

How could I manipulate this array in Javascript for this kind of error checking?

大兔子大兔子 提交于 2019-12-02 11:19:38
How can I make Javascript check an array and make sure that there's no error commited after the comma separating each element of the array .. For example a user may form an array with two commas in a row separating an element instead of one comma .. Not just comma , any other wrong input. var cars=["Saab",,"Volvo","BMW"]; // Here , this array has an error , there's a double comma . var cars=["Saab",*"Volvo","BMW"]; // this array has an error , there's an axterix. var cars=["Saab","Volvo","BMW"]; // this array is the right one. Here's the wrong array What javascript function or solution could I

Any even to detect when the “Class” attribute is changed for a control

风格不统一 提交于 2019-12-02 09:33:19
I have a "div" control with some id="myDiv" class="myClass" var var1=10; in Javascript based on user action i will change the class for this control form "myClass" to "newClass" so when this is happened i want to change the value of var1 to 20. So how would i recognize that change in Class. Thanks in advance You may use onpropertychange (IE) and DOMAttrModified (others) You'll have to use 3 things: onpropertychange event, for IE < 9 DOMAttrModified , works in IE9, Opera, Firefox, and not regrettably in all others as Dr.Molle suggests Everything else - must resort to setInterval loop , that

Sorting array using Javascript function - Understanding

会有一股神秘感。 提交于 2019-12-02 06:00:23
I decided to get shuffled values from array. for that i used this function, i got it from net, it works fine. But i don't know, how it's works... any one can help me to understand this? my code is : function rand(ar){ return 0.5-Math.random(); } var ar = [5,10,15,20,25] ar.sort(rand); console.log(ar) I am using this function for getting new shuffled array values from the declared one. This code is using the supplied rand function as the comparison operator for the Array.Sort method ( http://msdn.microsoft.com/en-us/library/4b4fbfhk(VS.85).aspx ). Since the Math.random ( http://msdn.microsoft

How to use javascript namespaces correctly in a View / PartialView

杀马特。学长 韩版系。学妹 提交于 2019-12-01 20:43:54
i've been playing with MVC for a while now, but since the project i'm on is starting to get wind in its sails more and more people are added to it. Since i'm in charge of hacking around to find out some "best practice", i'm especially wary about the possible misuses of javascript and would like to find out what would be the best way to have our views and partial views play nicely with javascript. For the moment, we're having code that looks like this (only simplified for example's sake) <script type="text/javascript"> function DisableInputsForSubmit() { if ($('#IsDisabled').is(':checked')) { $

Storing JSON data in browser memory

一曲冷凌霜 提交于 2019-12-01 16:09:37
I want to persist some JSON information in browser. Depending on user interaction with the application, I want to store 5-6 different JSON object into memory. What options I have to achieve this? Please suggest any library or plugin using which I can persist information in the browser. Thanks Rupam Datta To add to the solutions given, I'd also want to add a reference link Storing Objects in HTML5 localStorage where this question is discussed nicely. Below is the code var testObject = { 'one': 1, 'two': 2, 'three': 3 }; // Put the object into storage localStorage.setItem('testObject', JSON

jQuery/Javascript framework efficiency

隐身守侯 提交于 2019-12-01 13:20:31
My latest project is using a javascript framework (jQuery), along with some plugins (validation, jquery-ui, datepicker, facebox, ...) to help make a modern web application. I am now finding pages loading slower than I am used to. After some js profiling (thanks VS2010!), it seems a lot of the time is taken processing inside the framework. Now I understand the more complex the ui tools, the more processing needs to be done. The project is not yet at a large stage and I think would be average functions. At this stage I can see it is not going to scale well. I noticed things like the 'each'

Disable specific function key using jquery

倾然丶 夕夏残阳落幕 提交于 2019-12-01 12:38:07
I want to disable F8 key on my web page. Is there any way I can disable it using jquery or any associated plugins or just javascript?? Thanks in advance... :) blasteralfred mplungjan Like this Disable F5 key in Safari 4 but using keyCode 119: <script> var fn = function (e) { if (!e) var e = window.event; var keycode = e.keyCode; if (e.which) keycode = e.which; var src = e.srcElement; if (e.target) src = e.target; // 119 = F8 if (119 == keycode) { alert('nope') // Firefox and other non IE browsers if (e.preventDefault) { e.preventDefault(); e.stopPropagation(); } // Internet Explorer else if (e

panel drag and drop is not working in extjs 4.1

拥有回忆 提交于 2019-12-01 11:59:51
This code is working in Extjs 4.0.2a but when converted to 4.1 it no longer works and gives an error Uncaught TypeError: Cannot call method 'query' of undefined Ext.onReady(function() { var panel = new Ext.Panel({ renderTo: divtag, draggable: { insertProxy: false, onDrag: function(e) { var el = this.proxy.getEl(); this.x = el.getLeft(true); this.y = el.getTop(true); }, endDrag: function(e) { this.panel.setPosition(this.x, this.y); } }, title: 'Panel', width: 200, height: 100, x: 20, y: 20 }); }); Apparently there is a bug in this version of Ext. It wont work even if you try default D'n'D for