Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 占位符属性在internet explorer中不起作用_Javascript_Internet Explorer_Placeholder - Fatal编程技术网

Javascript 占位符属性在internet explorer中不起作用

Javascript 占位符属性在internet explorer中不起作用,javascript,internet-explorer,placeholder,Javascript,Internet Explorer,Placeholder,占位符在InternetExplorer中不起作用的问题的解决方案如下:使用javascript和jquery的组合 //DETERMINE BROWSER TYPE var browser=''; jQuery.each(jQuery.browser, function(i, val) { if(i=='msie')browser=i; }); if(browser=='msie'){ var password = '&

占位符在InternetExplorer中不起作用的问题的解决方案如下:使用javascript和jquery的组合

    //DETERMINE BROWSER TYPE
    var browser='';
    jQuery.each(jQuery.browser, function(i, val) {
        if(i=='msie')browser=i;
    });

    if(browser=='msie'){
        var password = '<input type="text" value="Password" placeholder="Password" name="q22" class="form-gen-element" id="ie-password-holder" />';

        $(password)
        .insertAfter($('input[name="q2"]'));

        $('input[name="q2"]')
        .hide();

        //INTERNET EXPLORER PLACEHOLDER FIX
        $('#login-content')
        .find('.form-gen-element')
        .focus(function(){
            if($(this).val()==$(this).attr('placeholder')){
                //Move cursor position
                if ($(this).get(0).setSelectionRange) {
                  $(this).get(0).setSelectionRange(0, 0);
                } else if ($(this).get(0).createTextRange) {
                  var range = $(this).get(0).createTextRange();
                  range.collapse(true);
                  range.moveEnd('character', 0);
                  range.moveStart('character', 0);
                  range.select();
                }
            }
        })
        .blur(function(){
            if($(this).val()==''){
                $(this).val($(this).attr('placeholder'));

                if($(this).attr('name')=='q2')
                    $(this).attr('type','text');
            }
        })
        .keydown(function(e){
            if($(this).val()==$(this).attr('placeholder')){
                if((e.keyCode > 47 && e.keyCode < 91) || e.keyCode==109 || e.keyCode==110 || e.keyCode==190 || e.keyCode==110){
                    var t = $(this).val().split($(this).attr('placeholder'));
                    $(this).val(t[0]);

                    //Handle password attribute change
                    if($(this).attr('name')=='q22'){
                        $(this).attr('type','password');
                    }
                }
            }
        });

    }else{
        //OTHER BROWSERS DEFAULT FUNCTIONALITY
        $('#login-content')
        .find('.form-gen-element')
        .val('');
    }
});
我必须重申,占位符在InternetExplorer中不起作用的问题的解决方案如下:使用javascript和jquery的组合

    //DETERMINE BROWSER TYPE
    var browser='';
    jQuery.each(jQuery.browser, function(i, val) {
        if(i=='msie')browser=i;
    });

    if(browser=='msie'){
        var password = '<input type="text" value="Password" placeholder="Password" name="q22" class="form-gen-element" id="ie-password-holder" />';

        $(password)
        .insertAfter($('input[name="q2"]'));

        $('input[name="q2"]')
        .hide();

        //INTERNET EXPLORER PLACEHOLDER FIX
        $('#login-content')
        .find('.form-gen-element')
        .focus(function(){
            if($(this).val()==$(this).attr('placeholder')){
                //Move cursor position
                if ($(this).get(0).setSelectionRange) {
                  $(this).get(0).setSelectionRange(0, 0);
                } else if ($(this).get(0).createTextRange) {
                  var range = $(this).get(0).createTextRange();
                  range.collapse(true);
                  range.moveEnd('character', 0);
                  range.moveStart('character', 0);
                  range.select();
                }
            }
        })
        .blur(function(){
            if($(this).val()==''){
                $(this).val($(this).attr('placeholder'));

                if($(this).attr('name')=='q2')
                    $(this).attr('type','text');
            }
        })
        .keydown(function(e){
            if($(this).val()==$(this).attr('placeholder')){
                if((e.keyCode > 47 && e.keyCode < 91) || e.keyCode==109 || e.keyCode==110 || e.keyCode==190 || e.keyCode==110){
                    var t = $(this).val().split($(this).attr('placeholder'));
                    $(this).val(t[0]);

                    //Handle password attribute change
                    if($(this).attr('name')=='q22'){
                        $(this).attr('type','password');
                    }
                }
            }
        });

    }else{
        //OTHER BROWSERS DEFAULT FUNCTIONALITY
        $('#login-content')
        .find('.form-gen-element')
        .val('');
    }
});
//确定浏览器类型
var='';
每个(jQuery.browser,函数(i,val){
如果(i=='msie')浏览器=i;
});
如果(浏览器=='msie'){
var密码=“”;
$(密码)
.insertAfter($('input[name=“q2”]);
$('input[name=“q2”]”)
.hide();
//INTERNET EXPLORER占位符修复程序
$(“#登录内容”)
.find(“.form gen元素”)
.focus(函数(){
if($(this.val()==$(this.attr('placeholder')){
//移动光标位置
if($(this).get(0).setSelectionRange){
$(this.get(0).setSelectionRange(0,0);
}else if($(this).get(0).createTextRange){
var range=$(this.get(0.createTextRange();
范围。塌陷(真);
range.moveEnd('character',0);
range.moveStart('character',0);
range.select();
}
}
})
.blur(函数(){
if($(this.val()=''){
$(this.val($(this.attr('placeholder'));
if($(this.attr('name')=='q2')
$(this.attr('type','text');
}
})
.keydown(功能(e){
if($(this.val()==$(this.attr('placeholder')){
如果((e.keyCode>47&&e.keyCode<91)| e.keyCode==109 | e.keyCode==110 | e.keyCode==190 | e.keyCode==110){
var t=$(this.val().split($(this.attr('placeholder'));
$(this.val(t[0]);
//处理密码属性更改
if($(this.attr('name')=='q22'){
$(this.attr('type','password');
}
}
}
});
}否则{
//其他浏览器默认功能
$(“#登录内容”)
.find(“.form gen元素”)
.val(“”);
}
});

查看以下SO的有用问题