Domanda

<head></head>

<body>
    <input type="text" id="description"></input>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="http://www.steamdev.com/zclip/js/jquery.zclip.min.js"></script>
    <script>
        $(document).ready(function() {
            $('a#copy').zclip({
                path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
                copy: $(text#description).text()
            });
        });
    </script>
    <button type="button"><a id='copy' href="#">Copy</a></button>

</body>

I think i have it mostly figured out but i don't know why its not working... could you help me out? Instead of zero clipboard i used another library called zclip ( http://www.steamdev.com/zclip/). here's my code : http://jsfiddle.net/3GVX9/1/ thanks in advance! Ps I want to make it so after you click the button it copies the text in the text feild to your clipboard.

È stato utile?

Soluzione

Your code isn't syntactically valid: the selector string is not delimited by quotes.

copy: $('text#description').text()

Your selector is also invalid. It's trying to select a <text> element, when you should be selecting an <input> element. Since you've got an ID already, there's no reason to write a more-specific selector, anyway.

copy: $('#description').text()

You also need to get the text to copy when the button is clicked, not when the page loads.

copy: function() {
    return $('#description').text();
}

But we're dealing with a form input field, so use .val() instead of .text():

copy: function() {
    return $('#description').val();
}

and lastly, you need to set up the fiddle correctly.

Here's a working demo: http://jsfiddle.net/mattball/kqKTG

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top