简体   繁体   English

jQuery javascript此函数未调用

[英]jquery javascript this function is not calling

I have this java script function: 我有这个Java脚本功能:

function copyToClipboardCrossbrowser2(text) {
    alert(text);
    $('#Button1').zclip({
        path: '/js/ZeroClipboard.swf',
        copy: text
    });
}

when I make path: js/ZeroClipboard.swf , google chrome tells me that this file is not exist. 当我创建path: js/ZeroClipboard.swf ,谷歌浏览器告诉我该文件不存在。 but when I put the / it doesn't tell me that it is not working. 但是当我输入/ ,并没有告诉我它不起作用。 so the swf is installed. 这样就安装了swf。

the alter is printing the correct value. 更改将打印正确的值。 but the copy is not working. 但该副本无效。

why please? 告诉我为什么?

I already include these: 我已经包括了:

 <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/jquery.zclip.js"></script>

Note 注意

In another project, I am working with this library, which means my flash player is working 在另一个项目中,我正在使用此库,这意味着我的Flash Player正在运行

This is the html of the button that has the id Button 这是具有id Button的按钮的html

<button type="button" id="Button1" class="copyToBtn" onclick="copyToClipboardCrossbrowser2('00971509396782',this);" title="Copy">
                                Copy Phone Number</button>

I am working asp.net and this is the code of the button 我正在asp.net,这是按钮的代码

<button type="button" id="Button1" class="copyToBtn" type="button" onclick="copyToClipboardCrossbrowser2('<%#Eval("Telephone")%>',this);"
                                title="Copy">
                                Copy Phone Number</button>

The id is not changing that is why I gave you the html id没有改变,这就是为什么我给你html

js fiddle: js小提琴:

http://jsfiddle.net/6HPuC/ http://jsfiddle.net/6HPuC/

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/zclip/1.1.2/jquery.zclip.min.js"></script>
    <title>Test</title>
</head>        
<script>
    $(function() {
        $("#Button1").zclip({
            path: 'http://cdnjs.cloudflare.com/ajax/libs/zclip/1.1.2/ZeroClipboard.swf',
            copy: function() {
                return $(this).data("copy");
            }
        });
    });
</script>
</head>
<body>
<button type="button" data-copy="<%#Eval('Telephone')%>" id="Button1" class="copyToBtn" title="Copy">Copy Phone Number</button>
</body>
</html>

In your code you have used on button click event to bind zClip with button which is Wrong. 在您的代码中,您使用了on button click事件将zClip与错误的按钮绑定。 When you attach ZClip to button it will automatically handles OnClick event, no need to write on button event 当您将ZClip附加到按钮时,它将自动处理OnClick事件,而无需编写按钮事件

Below is your modified code 下面是修改后的代码

 <script type="text/javascript">
    $(document).ready(function () {
        $('#Button1').zclip({
            path: '/js/ZeroClipboard.swf',
            copy: $('#Button1').attr('data-copy')
        });        
    });

</script>

And button event will be as below: 和按钮事件将如下所示:

<button type="button" id="Button1" class="copyToBtn" data-copy="<%#Eval('Telephone')%>" title="Copy">
            Copy Phone Number</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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