开发者

Why would javascript work on my Sony Ericsson C510 browser, but not javascript + jquery?

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">

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>
</ht开发者_JAVA技巧ml>

How can I get jquery to work in my Sony Ericsson C510 browser as plain javascript does?

Added:

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>

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.


The C510 browser is NetFront 3.4.

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 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.


jQuery isn't supported on all mobile devices. I've been able to get it working on iPhone, iPod Touch, most Android phones, Palm Pre and -i think- Blackberry.

John Resig is working on a mobile version though, check out http://groups.google.com/group/jquery-dev/browse_thread/thread/6d0f9da66581d9ca/819ff599f546ec65?lnk=raot&pli=1

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜