IE8切换src属性不支持一下代码

 

现在想做上传图片前的预览功能,可是我发现使用JS动态写入Img标签的SRC属性值,在IE6和FF3下没有问题,只有IE7和IE8下少数可以显示,可以看下面代码 ,看起来好像很有道理,但是在IE8下却是不支持的 

 

<i class="parent_position_login">
    <img src="images/no_remenber.png" alt="" class="remenber_img"/>
    <input type="checkbox" id="rem_pwd"/> 记住密码
</i>
$('.remenber_img').click(function(){
    if($(this).attr('src')=='images/no_remenber.png'){
        $(this).attr('src','images/remenber.png');
        $('#rem_pwd').attr("checked","true");
        console.log( $('#rem_pwd').attr("checked"))
    }else{
        $(this).attr('src','images/no_remenber.png');
        $('#rem_pwd').removeAttr("checked");
        console.log( $('#rem_pwd').attr('checked'))
    }
})

再来看下面这段代码,不光看着有道理 ,用着也有道理,没有兼容性问题了就 ,曲线救国的一种 ~

<img src="images/no_remenber.png" alt="" onclick="check(this)" index="1" class="remenber_img">
<input type="checkbox" id="checkbox" /> 记住密码
function check(e) {
    var index=e.getAttribute('index');
    var icon=document.getElementById("checkbox");
    if (index=='1') {
        e.setAttribute('index', '0');
        e.src="images/remenber.png";
        icon.checked=true;
        console.log( icon.checked)
    } else {
        e.setAttribute('index', '1');
        icon.checked=false;
        e.src="images/no_remenber.png";
        console.log( icon.checked)
    }
}

 

posted @ 2017-12-11 17:33  芊芊公子  Views(232)  Comments(0)    收藏  举报