简体   繁体   中英

JavaScript function doesn't work in IE?


I'm having a lot of problems with IE7/IE8 and Javascript/jQuery, which I don't have in Chrome or FireFox.
I have this Javascript function:

function changeImg(img,bla){
    $('#open_case').css("background-image", "url('"+img+"')");
    getIngo(bla);
    navigation_image(bla);
}

And this is my onclick function:

<div class="cImage" style="background-image:url('http://bla.com/images/this_image.jpg');" onclick="changeImg('http://bla.com/images/this_image.jpg','2');"></div>

But it's like the function isn't called at all, 'cause if I change the changeImg function to an alert function:

function changeImg(img,bla){
    alert('hi!');
}

It still doesn't work.
The only error IE7/IE8 gives is Expecting Object (roughly translated)
What am I doing wrong?
Thanks in advance!

[Edit:]
These are lines IE7/IE8 is pointing at;

<script type="text/javascript" src="Scripts/swfobject.js"></script>
<script type="application/javascript" language="javascript">
function clearText(textfield){
    if (textfield.defaultValue == textfield.value){
        textfield.value = '';
        $(textfield).css('color','#000000');
    }
}
function addText(textfield){
    if (textfield.value == ''){
        textfield.value = textfield.defaultValue;
        $(textfield).css('color','#999999');
    }
}

If the error is object expected. Then try this

Change your

<script type="application/javascript" language="javascript">

To

<script type="text/javascript">

Is there a reason you're using javascript here? It looks like you're changing the image on a navigation item? You could just just the CSS :hover classes . Regardless, using onmouseover isn't really the "proper" way to be handling this sort of thing in javascript, if you really cannot use just CSS, at the very least look into handling the mouse over envent properly in jQuery .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM