为什么javascript在我的索尼爱立信C510浏览器上可以工作,而在javascript + jquery上却不能工作? [英] Why would javascript work on my Sony Ericsson C510 browser, but not javascript + jquery?

查看:72
本文介绍了为什么javascript在我的索尼爱立信C510浏览器上可以工作,而在javascript + jquery上却不能工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将以下.htm文件复制到我的索尼爱立信C510,并且鼠标悬停可以工作:

I'm able to copy the following .htm file to my sony ericsson C510 and the mouseover works:

<script type="text/javascript">
    <!--
    if (document.images) {
        front = new Image
        back = new Image

        front.src = "front.png"
        back.src = "back.png"
    }
    function swapImage(thisImage,newImage) {
        if (document.images) {
            document[thisImage].src = eval(newImage + ".src")
        }
    }
    -->
</script>
<img onMouseOver="swapImage('test','back')"
onMouseOut="swapImage('test','front')"
 src="front.png"
    border="0"
    name="test">

但是我无法使用任何jquery,例如当我单击链接时,以下示例不响应.我知道jquery-1.4.2.min.js文件在正确的位置,因为我将所有文件复制到了目录中:

But I can't get any jquery to work, e.g. the following example does not respond when I click on the links. I know the jquery-1.4.2.min.js file exists in the right place because I copied all the files in the directory:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function() {
            $("div > div.question").click(function() {
                if($(this).next().is(':hidden')) {
                $(this).next().show();
                } else {
                $(this).next().hide();
                }
            });    
            });

        </script>
        <style>
            div.flashcard {
                margin: 0 10px 10px 0;
            }
            div.flashcard div.question {
                background-color:#ddd;
                width: 400px;        
                padding: 5px;    
                cursor: hand;    
                cursor: pointer;
            }
            div.flashcard div.answer {
                background-color:#eee;
                width: 400px;
                padding: 5px;    
                display: none;        
            }
        </style>
    </head>

<body>
    <div id="1" class="flashcard">
    <div class="question">Who was Wagner?</div>
    <div class="answer">German composer, conductor, theatre director and essayist, primarily known for his operas (or "music dramas", as they were later called). Unlike most other opera composers, Wagner wrote both the music and libretto for every one of his works.</div>
    </div>

    <div id="2" class="flashcard">
    <div class="question">Who was Thalberg?</div>
    <div class="answer">a composer and one of the most distinguished virtuoso pianists of the 19th century.</div>
    </div>
</body>
</html>

如何像普通的JavaScript一样使jquery在索尼爱立信C510浏览器中工作?

根据rchern的建议,我尝试了以下方法:

Based on rchern's suggestion, I tried this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function() { 
                $('#test').css("background-color","lightgreen");
                alert("hi from jQuery"); 
            });

        </script>
    </head>

<body>
<p>test from html</p>

<p id="test">jquery should turn this green</p>

</body>
</html>

在桌面上的firefox中,它显示弹出窗口并将行变成绿色,但是在手机jquery上似乎没有任何作用,只显示了文本.

In firefox on the desktop it shows the popup and turns the line green, but on the cell phone jquery seems to have no effect, only the text is shown.

推荐答案

C510浏览器为 NetFront 3.4.

The C510 browser is NetFront 3.4.

这肯定来自浏览器的老派,早在供应商认为提供有关所支持内容或调试工具的文档很有用之前.与其他较旧的移动浏览器一样,使用NetFront时,您实际上必须逐步进行功能测试,因为我们今天认为基本的JavaScript(不要紧DOM)已损坏,并且当出现问题时您几乎没有承受能力.弄清楚它是什么.

This is definitely from the old school of browsers, back before vendors considered it useful to provide documentation on what was supported, or debugging tools. With NetFront, like other older mobile browsers, you really have to work up incrementally testing features as you go, because some of what we would today consider basic JavaScript (never mind DOM) is broken, and when something goes wrong you have little affordance to work out what it was.

jQuery是一种复杂的野兽,它在JS和DOM允许的范围内具有一些自由.我不希望它能在当前的智能手机(WinMo 6.1.4 +,iPhone,Android等)出现之前在移动浏览器上运行.抱歉.

jQuery is a complex beast that takes a few liberties with what JS and DOM allow. I would not expect it to work on mobile browsers prior to the current crop of smartphones (WinMo 6.1.4+, iPhone, Android etc). Sorry.

这篇关于为什么javascript在我的索尼爱立信C510浏览器上可以工作,而在javascript + jquery上却不能工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆