Why does the onclick event get this.src in js img without domain name?

function del (obj) {

console.log(obj.src);//srchttp
var img = document.getElementById("recommendimgs").value;
    var imgsArr = img.split(",");
    for(var i =0; i<imgsArr.length; iPP){
        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);

}

now I want to match later and delete it. I want to know how onclick can get the src of the current picture without http, not to mention jq

Mar.01,2021

get the src attribute value directly:

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

you can also remove the domain name of obj.src

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


take the value of this attribute when saving a src-source, fetch in the element

Menu