开发者

write css property pbackground in js ,cant work in firefox

开发者 https://www.devze.com 2023-03-30 14:28 出处:网络
this js funciton: function(strIDHead) { var leftTD =开发者_如何转开发 document.getElementById(strIDHead + \"_left\");

this js funciton:

function(strIDHead) {
    var leftTD =开发者_如何转开发 document.getElementById(strIDHead + "_left");
    if (leftTD != null) {
        leftTD.background = "Images/Button/button_left.gif";
    }
}

can only work in ie,i want it work in firefox,how to do it? ps:i tried

if (leftTD != null) leftTD.background = "url(/Images/Button/button_left.gif)";

cant work either...


Try this:

if (leftTD) leftTD.style.background = "url(Images/Button/button_left.gif)";

Or if you can use jQuery (whole function, not just the last line):

$('#' + strIDHead + '_list').css('background', 'url(Images/Button/button_left.gif)');

Update: Your function header is incorerct, too, unless you want an anonymous function and just forgot to copy the code where it's assigned somewhere. The correct function would looke like this:

function someFunction(strIDHead) {
    var leftTD = document.getElementById(strIDHead + "_left");
    if (leftTD) {
        leftTD.style.background = "url(Images/Button/button_left.gif)";
    }
}
0

精彩评论

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

关注公众号