Thursday, May 22, 2014

Tips for JS

Instagram
Seacrh a value exists in string or array  (indexOf()
 
var str = "Hello world";
var n = str.indexOf("world")

This will return 2 for n. (Position of search key "world").
For not existing values this function will return -1.  ;)

* When delete an item in array always use splice instead of delete. Coz delete will replace the deleted item from undefined but splice not.

============================================================================
Disable Backspace and delete key

Insert following code in JS file

function disableBackspace(evt, obj) {
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if ((charCode == 8 || charCode == 46) && clientMaskcurr.length >=   obj.selectionEnd ) return false;
    return true;
}


Insert following code in HTML related input

<input disableBackspace(event,this) .... >

No comments:

Post a Comment