Javascript:更改图像元素的边框颜色?

Javascript:更改图像元素的边框颜色?,javascript,Javascript,在我的javascript代码中,我希望在第一个图像被隐藏以显示绿色边框之后,将图像元素作为目标?代码似乎运行时没有错误输出?我错过了什么 以下是html: <img src="black_cat.jpg" alt="Profile Pic" height="300" width="300" id="profile_pic"></img> <img src="white_cat.jpg" alt="Profile Pic" height="300" widt

在我的javascript代码中,我希望在第一个图像被隐藏以显示绿色边框之后,将图像元素作为目标?代码似乎运行时没有错误输出?我错过了什么

以下是html:

<img src="black_cat.jpg" alt="Profile Pic" height="300" width="300" id="profile_pic"></img>
    <img src="white_cat.jpg" alt="Profile Pic" height="300" width="300" id="next_profile"></img>
    <img src="" alt="Swipe Left" height="150" width="150" id="swipe_left" onclick="hide_profile(); show_profile(); update_pic('swipe_left');"></img>
    <img src="" alt="Swipe Right" height="150" width="150" id="swipe_right" onclick="hide_profile(); show_profile(); update_pic();"></img>
    <p id="display_message"></p>

这是因为您指定了颜色,但没有指定大小。您可以使用
边框
属性同时设置颜色、大小和样式

函数隐藏配置文件(){
document.getElementById(“profile_pic”).style.visibility=“hidden”;
}
函数show_profile(){
document.getElementById(“下一个配置文件”).style.display=“块”;
document.getElementById(“下一个配置文件”).style.visibility=“可见”;
document.getElementById(“profile_pic”).style.display=“无”;
}
功能更新图片(id){
如果(id='swipe_left'){
document.getElementById(“display_message”).innerHTML=“你不喜欢这只猫!”;
document.getElementById('next_profile')。style.border='solid 1px green';
}否则{
document.getElementById(“display_message”).innerHTML=“你喜欢这只猫!”;
}
}


这是因为您指定了颜色而不是大小。您可以使用
边框
属性同时设置颜色、大小和样式

函数隐藏配置文件(){
document.getElementById(“profile_pic”).style.visibility=“hidden”;
}
函数show_profile(){
document.getElementById(“下一个配置文件”).style.display=“块”;
document.getElementById(“下一个配置文件”).style.visibility=“可见”;
document.getElementById(“profile_pic”).style.display=“无”;
}
功能更新图片(id){
如果(id='swipe_left'){
document.getElementById(“display_message”).innerHTML=“你不喜欢这只猫!”;
document.getElementById('next_profile')。style.border='solid 1px green';
}否则{
document.getElementById(“display_message”).innerHTML=“你喜欢这只猫!”;
}
}


您需要添加其他边框样式,包括宽度和样式

function hide_profile() {
        document.getElementById("profile_pic").style.visibility = "hidden";
    }

function show_profile() {
    document.getElementById("next_profile").style.display = "block";
    document.getElementById("next_profile").style.visibility = "visible";
    document.getElementById("profile_pic").style.display = "none";
}

function update_pic(id) {
    if (id == 'swipe_left') {
        document.getElementById("display_message").innerHTML = "You didn\'t Like this Cat!";

        // look here!
        document.getElementById("next_profile").style.border = "1px solid green";

    } else {
        document.getElementById("display_message").innerHTML = "You Liked this Cat!";
    }
}

小提琴:

您需要添加其他边框样式,包括宽度和样式

function hide_profile() {
        document.getElementById("profile_pic").style.visibility = "hidden";
    }

function show_profile() {
    document.getElementById("next_profile").style.display = "block";
    document.getElementById("next_profile").style.visibility = "visible";
    document.getElementById("profile_pic").style.display = "none";
}

function update_pic(id) {
    if (id == 'swipe_left') {
        document.getElementById("display_message").innerHTML = "You didn\'t Like this Cat!";

        // look here!
        document.getElementById("next_profile").style.border = "1px solid green";

    } else {
        document.getElementById("display_message").innerHTML = "You Liked this Cat!";
    }
}

Fiddle:

FYI图像是自动关闭的
。没有
边框是否以宽度开头?@j08691实际上,关闭所有标记是有效的XHTML;)仅供参考的图像是自动关闭的
。没有
边框是否以宽度开头?@j08691实际上,关闭所有标记是有效的XHTML;)