javascript - IF statement doenst work -
i've got function dont know if "switch" better?
(function ($) {     var doc = $.urlparam('doc');     if (doc) {         if (doc = 'new') {             alert(doc);         }         if (doc = 'new2') {             alert(doc);         }         if (doc = 'new3') {             alert(doc);         }     } })(jquery);   the alert should show if parameter in url right, in if statement.
the complete code can found here: https://jsfiddle.net/yc5f9ct7/4/
as pointed out, using assignment = instead of comparison == or exact comparison ===.
that aside, if testing 1 variable multiple values, , intend have different code on each, switch more logical:
var doc = $.urlparam('doc'); switch (doc){     case 'new':         alert(doc);         break;     case 'new2':         alert(doc);         break;     case 'new3':         alert(doc);         break; }   also note: looks code wants wrap last part in dom ready handler too, wrapping in iife instead. change wrapper jquery(function($){ code here });
e.g.
jquery(function($){     var doc = $.urlparam('doc');     switch (doc){         case 'new':             alert(doc);             break;         case 'new2':             alert(doc);             break;         case 'new3':             alert(doc);             break;     } });   this handy shortcut dom ready, provides locally scoped $.
Comments
Post a Comment