无法使jsFiddle示例工作

时间:2013-01-26 13:41:50

标签: jquery html jquery-mobile jsfiddle

我希望在我的网站上找到相同的功能:http://jsfiddle.net/jhruh/2/

我不明白为什么如果我复制所有我没有获得相同功能的东西。我所做的步骤是:

  1. 复制HTML
  2. 在我在步骤1中复制的html的头部添加了jquery库(<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  3. 添加了一个脚本标记作为包含jsFiddler代码的body标记的最后一个子标记。
  4. 在JavaScript代码之上添加了jquery $(function(){})。
  5. 换句话说,我现在有:

    <!DOCTYPE html>
    <html>
    <head>
        <title>jQM Complex Demo</title>
        <meta name="viewport" content="width=device-width" />
    
        <!-- Step 2 -->
        <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-role="header">
                <h1>
                    XML Parsing demo</h1>
            </div>
            <div data-role="content">
                <ul data-role="listview" data-inset="true" id="cars-data">
                </ul>
            </div>
        </div>
        <div data-role="page" id="cars">
            <div data-role="header">
                <a data-role="button" data-transition="none" data-theme="a" href="#index">Back</a>
                <h1>
                </h1>
            </div>
            <div data-role="content">
                <ul data-role="listview" data-inset="true" id="car-data">
                </ul>
                <img src="" width="100%" style="height: auto;" id="car-img" />
            </div>
        </div>
    
        <!-- Step 3 -->
        <script>
    
            // <!-- Step 4 // do stuff after DOM has loaded -->
            $(function () {
    
                $('#index').live('pagebeforeshow', function (e, data) {
                    $('#cars-data').empty();
                    $.ajax({
                        type: "POST",
                        url: "InvalidUrlCreatedOnPurpose",
                        dataType: "xml",
                        data: {
                            xml: "<cars><car><name>TOYOTA</name><country>JAPAN</country><pic>http://1call.ms/Websites/schwartz2012/images/toyota-rav4.jpg</pic><description>Toyota has announced that it will recall a total of 778,000 units that may have been manufactured with improperly-tightened nuts on the rear suspension.</description></car></cars>"
                        },
                        success: function (xml) {
    
    
                            var xmlstr = (new XMLSerializer()).serializeToString(xml);
                            alert(xmlstr);
    
                            alert(xml);
                            ajax.parseXML(xml);
    
                        },
                        error: function (request, error) {
                            alert('Remember to remove this message once it works!');
                            var x = "<cars><car><name>TOYOTA</name><country>JAPAN</country><pic>http://1call.ms/Websites/schwartz2012/images/toyota-rav4.jpg</pic><description>Toyota has announced that it will recall a total of 778,000 units that may have been manufactured with improperly-tightened nuts on the rear suspension.</description></car></cars>";
                            ajax.parseXML(x);
                        }
                    });
                });
    
                $("#cars").live('pagebeforeshow', function () {
                    $("#cars div[data-role='header'] h1").html(carObject.carName);
                    $('#car-data').empty();
                    $('#car-data').append('<li>Car Type:<span> ' + carObject.carName + '</span></li>');
                    $('#car-data').append('<li>Car Country:<span> ' + carObject.carCountry + '</span></li>');
                    $('#car-data').append('<li>Car Description:<span> ' + carObject.description + '</span></li>');
                    $('#car-data').listview('refresh');
                    $('#car-img').attr('src', carObject.img);
    
                });
    
                var ajax = {
                    parseXML: function (result) {
                        $(result).find("car").each(function () {
                            carObject.carName = $(this).find('name').text();
                            carObject.carCountry = $(this).find('country').text();
                            carObject.img = $(this).find('pic').text();
                            carObject.description = $(this).find('description').text();
    
                            $('#cars-data').append('<li><a href="#cars"><img src="' + carObject.img + '" title="sample" height="100%" width="100%"/><h3>Car type:<span> ' + carObject.carName + '</span></h3><p>' + carObject.description + '</p></a></li>');
                        });
                        $('#cars-data').listview('refresh');
                        $('#index').append('<div data-role="footer" data-position="fixed"><h1>Dynamicaly added footer</h1></div> ');
                        $('#index [data-role="content"]').append('<fieldset data-role="controlgroup"><legend>Choose:</legend><input type="radio" name="radio" id="radio1" value="1" checked="checked" /><label for="radio1">option 1</label></fieldset>');
                        $('#index').trigger('pagecreate');
                    }
                }
    
                var carObject = {
                    carName: '',
                    carCountry: '',
                    img: '',
                    description: ''
                }
    
            });
    
        </script>
    </body>
    </html>
    

    页面表现不同为什么?我知道jsFiddler可以使用url'echo'模拟ajax调用,但我故意模拟了一个错误,希望我能在我的网站上得到相同的结果。

    修改

    我更改了http://cdn1.iconfinder.com/data/icons/sleekxp/Google%20Chrome.png

    的图片来源

    我更新了jsFiddler,新的链接是:http://jsfiddle.net/jhruh/3/,我可以让它继续工作。

1 个答案:

答案 0 :(得分:1)

第33行,第74列:元素img上属性src的值不正确:必须为非空。              IRI参考语法: 任何网址。例如:/ hello,#scanvas或http://example.org/。字符应以NFC表示,空格应按%20进行转义。