html - indexOf method in jquery? -
i have lost of special character in var name"str" want user enter character within alert him "hiii" else "byeee" depending on indexof check of string
<head> <script type="text/javascript" src="jquery-1.7.2.js"></script> <script type="text/javascript"> $(function(){ $('#me').click(function(){ var amd=$('.text').val(); var str="[,],{,},<,>" if(amd.indexof(str)>-1){ alert('hiiiii') } else { alert('byee') } }) }) </script> </head> <body> <input type="text" class="text" /> <input type="button" value="click" id="me"/> </body>
you use regex match this, way, should add ; every end of line, habit.
$(function () { $('#me').click(function () { var amd = $('.text').val(); if (amd.match(/[\[\]{}<>]/)) { alert('hiiiii'); } else { alert('byee'); } }); });
Comments
Post a Comment