简体   繁体   English

JavaScript函数在IE中不起作用?

[英]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. 我在IE7 / IE8和Javascript / jQuery上遇到很多问题,而在Chrome或FireFox中却没有。
I have this Javascript function: 我有这个Javascript函数:

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

And this is my onclick function: 这是我的onclick函数:

<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: 但这就像根本没有调用该函数一样,因为如果我将changeImg函数更改为警报函数,则是:

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

It still doesn't work. 它仍然不起作用。
The only error IE7/IE8 gives is Expecting Object (roughly translated) IE7 / IE8给出的唯一错误是Expecting Object (粗略翻译)
What am I doing wrong? 我究竟做错了什么?
Thanks in advance! 提前致谢!

[Edit:] [编辑:]
These are lines IE7/IE8 is pointing at; 这些是IE7 / IE8指向的行;

<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? 您在这里使用JavaScript是否有原因? It looks like you're changing the image on a navigation item? 好像您要更改导航项上的图像? You could just just the CSS :hover classes . 您可以只使用CSS:hover类 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 . 无论如何,使用onmouseover并不是在javascript中处理这种事情的真正“正确”方式,如果您确实不能仅使用CSS,则至少要考虑在jQuery中正确处理鼠标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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