在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ js img里onclick事件獲取this.src怎么不帶域名

js img里onclick事件獲取this.src怎么不帶域名

<img src="/uploads/xxx.jpg" onclick="del(this)" />

function del(obj){

console.log(obj.src);//這里獲取的src是會帶http
var img = document.getElementById("recommendimgs").value;
    var imgsArr = img.split(",");
    for(var i =0; i<imgsArr.length; i++){
        console.log(imgsArr[i]);//這里的是不帶http
        if(imgsArr[i]==obj.src){
            imgsArr.splice(i,1);
        }
    }
    var imgStr = imgsArr.join(",");
    document.getElementById("recommendimgs").value=imgStr;
    obj.parentNode.removeChild(obj);

}

現(xiàn)在我想匹配以后到然后刪除掉,我想知道怎么onclick 怎么獲取當前圖片的src 不帶http的,別說用jq

回答
編輯回答
清夢

在元素中存入一個src-source, 取的時候取這個屬性的值

2017年1月15日 17:43
編輯回答
離殤

直接獲取src屬性值:

console.log(obj.getAttribute('src'))

也可以把obj.src的域名去掉

console.log(obj.src.replace(/http[s]?:\/\/[^\/]+/,''))

2017年7月10日 07:07