¿El código jsFiddle no se está ejecutando?

I am having a problem with this code - http://jsfiddle.net/B3XkD/1/

function itemInSpot(drag_item, spot) {
    var oldSpotItem = $(spot).find('img');
    if (oldSpotItem.length > 0) {
        oldSpotItem.appendTo('#inventory').draggable({
            revert: 'invalid'
        });
    }
    var item = $('<img />');
    item.attr('src', drag_item.attr('src')).attr('class', drag_item.attr('class')).appendTo(spot).draggable({
        revert: 'invalid'
    });
    drag_item.remove(); // Remove the old object
}

$(document).ready(function() {
    $(".circles").draggable({
        revert: 'invalid'
    });
    $('#inventory').droppable();
    $("#circles").droppable({
        accept: '.circles'
    })
    $('#circles,#inventory').bind('drop', function(ev, ui) {
        itemInSpot(ui.draggable, this);
    });
});

It runs perfect in jsFiddle, and when I copy the code onto web expression on my PC it doesn't work, only the HTML and CSS is applied, but there is no control of the images (JavaScript). What am I doing wrong?

preguntado el 09 de marzo de 12 a las 14:03

Any chance you aren't loading jQuery? -

hmm not sure, could you be more specific please, I only have the two files, html plus css in one, and javascipt and there is no errors -

it still doesnt work on my laptop, I am copying and pasting the code into web expression?? I dont have any control over the imgs -

im confident of that you forgot to implement the jquery file. please show your included files like css etc -

js file I have copied exacly as its there and css - { padding:0; margin:0; } p{ margin:10px; } body{ font-family:Verdana; font-size:12px; } img{ cursor: pointer; -

3 Respuestas

Compare the exact code created by jsFiddle with your site.

You can sign in to jsFiddle, hit [Run] and check the source of http://jsfiddle.net/draft/, alternatively you can check the source of http://fiddle.jshell.net/B3XkD/1/show/ (not secure to check fiddles created by someone else!).

respondido 11 mar '12, 08:03

Did you add jQuery and jQuery UI? jsFiddle adds them automatically but you'll have to do it manually in your local file:

Por ejemplo:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>

respondido 09 mar '12, 16:03

I still cant get it to work, dont know why, I have added the jquery and libary and nothing, I added these -código.jquery.com/jquery-1.7.1.js y ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js any ideas??? - user1259527

Sometimes jsFiddle (and JavaScript beautifiers) mess up the code. The very last semicolon is edited to a different character (but you can't see the difference). Delete the last semicolon (you will need to do TWO backspaces to get rid of it) and type a new one.

contestado el 08 de mayo de 13 a las 19:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.