简体   繁体   中英

document.ready() function not working

I am working for selecting the text from a text box to the clipboard with the help of zclip. But the document.ready() is not working. It is not even showing the alert. All required libraries are above the script tag and inside the head section. All the files are at the required positions.

I have even checked the files along with the full URL.

<script type="text/javascript" language="javascript">
$(document).ready(function(){
alert('hi');
        $("a#copy_initiator").zclip({
            alert('hi');
            path:"js/ZeroClipboard.swf",
           copy:function(){return $("input#copy-box").val();}
        });
    });
</script>


<a id="copy_initiator">Copy Link:</a> <input id="copy-box" type="text"  value="here_is_a_url" onfocus="this.select();">

you have a syntax problem here:

    $("a#copy_initiator").zclip({
        alert('hi');
        path:"js/ZeroClipboard.swf",
       copy:function(){return $("input#copy-box").val();}
    });

should be:

$("a#copy_initiator").zclip({
    path:"js/ZeroClipboard.swf",
    copy:function(){
        return $("input#copy-box").val();
    }
});

And better version:

$("#copy_initiator").zclip({
    path:"js/ZeroClipboard.swf",
    copy:function(){
        return $("#copy-box").val();
    }
});

Suggestion: use firebug to track these kind of issues.

you say "All required libraries", are you including several libraries ?

If this is the case, it could be possible that they are creating a conflict with jquery "$".

here is a webpage explaining this : https://api.jquery.com/jQuery.noConflict/

a test you can do, is going to your console entry in your browser's debugguer and try typing $('div'), or $('p'). If any of the html tags you select are recognize it means the $ is working, otherwise not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM