Getting img.src value (path name)

前端 未结 2 569
轮回少年
轮回少年 2021-01-13 03:34

I have a form for a registration page. The form contains an image that changes its src dependant on a situation. Within a script which activates upon submission of the form

相关标签:
2条回答
  • 2021-01-13 04:17

    Use this:

    if (document.getElementById('FName_Status').getAttribute('src') == "pictures/apic.png")
    
    0 讨论(0)
  • 2021-01-13 04:21

    Add an ID tag to your image (if it doesn't already have one), eg:

    <img src="pictures/apic.png" id="imageId" />
    

    Then you can reference it as follows:

    if (document.getElementById("imageId").src == "pictures/apic.png")
    {
        ...
    }
    

    EDIT

    Working example here: http://jsfiddle.net/2Wtkn/2/

    0 讨论(0)
提交回复
热议问题