如题:判断文本框中输入的内容是否包含\或/

解决方案 »

  1.   

    <input type="text" id="slash" value=""/>
    <input type="button" onclick="check()"/>
    <script type="text/javascript">
    function check(){
    var chk = document.getElementById('slash').value.search(/\/|\\/);
    if(chk != -1) alert("found it!")
    }
      

  2.   

    借用楼上的html<input type="text" id="slash" value=""/>
    <input type="button" onclick="check()"/>
    <script type="text/javascript">
    function check(){
        var str= document.getElementById('slash').value
        if(str.indexOf("\")!= -1&&str.indexOf("/")!= -1) alert("")
    }
      

  3.   


    function check(){
        if((/\/|\\/).test(document.getElementById('slash').value)) alert("found it!")
    }
      

  4.   


    <input type="text" id="slash" value=""/>
    <input type="button" onclick="check()"/>
    <script type="text/javascript">
    function check(){
        var results1 = document.getElementById('slash').value.indexOf("\");
           var results2 = document.getElementById('slash').value.indexOf("/");
        if(results1 != -1||results2!= -1) alert("有/或者\!")
    }