jQuery的加载另一个jQuery的时候按一下按钮 [英] jquery load another jquery when button click

查看:144
本文介绍了jQuery的加载另一个jQuery的时候按一下按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有特殊的情况下,我需要加载脚本时,一个按钮pressed,而不是当页面加载

我的按钮有 copySurName 作为ID
在我的剧本我有这样的:

  $(#copySurName)。点击(函数(){
});

在该脚本,我需要加载一个名为 CopyingScript 脚本存在于剧本服务器<文件夹/ p>

我使用asp.net

修改

这是我需要加载脚本

  $(文件)。就绪(函数(){    $('#键copySurName')。zclip({
        路径:'JS / ZeroClipboard.swf',
        副本:$。(TD:包含('姓'))下一个('TD')文本()
    });});

请注意,此脚本有一个的document.ready 功能,即不犯错误,对吧?


解决方案

将这个

  $(文件)。就绪(函数(){    $('#键copySurName')。zclip({
        路径:'JS / ZeroClipboard.swf',
        副本:$。(TD:包含('姓'))下一个('TD')文本()
    });});

在一个单独的的.js 文件。

和再做到这一点:

  $(#copySurName)。点击(函数(){
   $ .getScript('路径脚本文件'); //加载脚本并执行它
});

更多

I have special situation where I need to load the script when a button pressed, not when the page load

my button has copySurName as ID in my script I have this:

$("#copySurName").click(function () {
});

in that script, I need to load a script called CopyingScript exists in Script folder in the server

I am using asp.net

Edit

This is the script that I need to load

$(document).ready(function () {

    $('button#copySurName').zclip({
        path: 'js/ZeroClipboard.swf',
        copy: $("td:contains('Surname')").next('td').text()
    });

});

Please notice that this script has a document.ready function, that doesn't make mistakes, right?

解决方案

Put this

$(document).ready(function () {

    $('button#copySurName').zclip({
        path: 'js/ZeroClipboard.swf',
        copy: $("td:contains('Surname')").next('td').text()
    });

});

in a separate .js file.

And then do this:

$("#copySurName").click(function () {
   $.getScript('path to the script file'); // loads the script and executes it
});

Read more

这篇关于jQuery的加载另一个jQuery的时候按一下按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆