简体   繁体   English

代码在IE8中不起作用

[英]Code doesn't work in IE8

I'm using the following code to remove "http://" and "https://" from an user entered/pasted URL in a textbox: 我正在使用以下代码从文本框中用户输入/粘贴的URL中删除“ http://”和“ https://”:

$('input.url-input').change(

       function()
       {
           var textbox = $(this);

           if (textbox.val().indexOf("http://") == 0)
               textbox.val(textbox.val().substring(7));

           if (textbox.val().indexOf("https://") == 0)
               textbox.val(textbox.val().substring(8));

       });

My problem is it works in all browsers, including IE9 & IE10, but not in IE8. 我的问题是,它适用于所有浏览器,包括IE9和IE10,但不适用于IE8。

I'm new to Javascript and would appreciate your help. 我是Java语言的新手,非常感谢您的帮助。

Many thanks in advance! 提前谢谢了!

Works in IE7,8 use jQuery <= 1.10.x not 2.0.x 在IE7,8中可以使用jQuery <= 1.10.x而不是2.0.x

$('input[type=text].input-url').change( 
  function(event) {
      var $input, url;

      $input = $(this);
      url = $input.val();
      $input.val(url.replace(/^(http(s)?:\/\/)/i,''));          
 });

or short 或短

  $('input[type=text].input-url').change(  
    function(event) {
      $(this).val($(this).val().replace(/^(http(s)?:\/\/)/i,''));
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM