开发者

javascript form submit change submit button image

开发者 https://www.devze.com 2023-03-08 21:59 出处:网络
Here is my problem when i press the submit button in form the submit button change its image background css. however when i use mouseup to change its image again back to default it does not effect.

Here is my problem when i press the submit button in form the submit button change its image background css. however when i use mouseup to change its image again back to default it does not effect.

javascript code

window.onload = searchInit;

function searchInit(){

    document.getElementById('search_form').onsubmit = processForm;
    document.getElementById('submit_s').onmousedown = submitImageChange;
    document.getElementById('submit_s').onmouseup   = submitImageDefault;
}

function processForm()开发者_如何转开发{

    var a = document.getElementById('search_text');

    if(a.value.length > 0){
        return true;
    }else{ 
        return false;
    }

}

function submitImageChange(){

    this.style.backgroundImage = 'url(\'../image/button_background.jpg\')';
}

function submitImageDefault(){

    this.style.backgroundImage = 'url(\'../image/button_background2.jpg\')';

}

I hope you can help me..

Thank you


use css to change the background on the active state of the button:

#submit_s {
  background: url('../image/button_background2.jpg');
}

#submit_s:active {
  background: url('../image/button_background.jpg');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消