javascript document.ready() 函数不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22750988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:42:57  来源:igfitidea点击:

document.ready() function not working

javascriptjquery

提问by Tarsem Singh

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.

我正在 zclip 的帮助下从文本框中选择文本到剪贴板。但document.ready()不工作。它甚至没有显示警报。所有必需的库都位于脚本标记上方和 head 部分内。所有文件都在所需的位置。

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

我什至检查了文件以及完整的 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();">

采纳答案by Bilal

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.

建议:使用 firebug 来跟踪此类问题。

回答by montueron

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

如果是这种情况,他们可能会与 jquery "$" 产生冲突。

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

这是一个解释这个的网页: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.

您可以执行的测试是在浏览器的调试器中访问控制台条目并尝试键入 $('div') 或 $('p')。如果您选择的任何 html 标签被识别,则表示 $ 正在工作,否则不会。