小编dja*_*ngo的帖子

通过xhr进行JQuery ajax进展

我正在尝试捕获ajax请求的进度.我正在关注此链接中的文章http://www.dave-bond.com/blog/2010/01/JQuery-ajax-progress-HMTL5/.

它没有按预期工作.具有id progressCounter的div应该在其中包含%,据我所知,但在我的情况下没有任何反应.任何帮助?

在我看来,似乎if (evt.lengthComputable) {没有工作XHR

JSFIDDLE: http ://jsfiddle.net/bababalcksheep/r86gM/

HTML:

<div id="progressCounter"></div><br>
<div id="loading">Loading</div><br>
<div id="data"></div>
Run Code Online (Sandbox Code Playgroud)

JS:

var progressElem = $('#progressCounter');
var URL = "https://api.github.com/users/mralexgray/repos";
$("#loading").hide();
// write something in #progressCounter , later will be changed to percentage
progressElem.text(URL);

$.ajax({
    type: 'GET',
    dataType: 'json',
    url: URL,
    cache: false,
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.responseText);
        alert(thrownError);
    },
    xhr: function () {
        var xhr = new window.XMLHttpRequest();
        //Download progress
        xhr.addEventListener("progress", function (evt) { …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

23
推荐指数
1
解决办法
7万
查看次数

jQuery在一定时间后删除引导警报

我正在使用示例中的动态引导警报.见下文.

如何添加超时功能,以便在X时间后警报自动关闭?

HTML:

<div id="alert_placeholder"></div>
Run Code Online (Sandbox Code Playgroud)

JQUERY:

bootstrap_alert = function() {
    }
bootstrap_alert.warning = function(message) {
    $('#alert_placeholder').append('<div class="alert alert-block fade in"><button type="button" class="close" data-dismiss="alert">&times;</button><h4>Info!</h4>'+ message +'</div>');
}
bootstrap_alert.info = function(message) {
    $('#alert_placeholder').append('<div class="alert alert-block alert-info fade in"><button type="button" class="close" data-dismiss="alert">&times;</button><h4>Info!</h4>'+ message +'</div>');
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery timeout twitter-bootstrap

6
推荐指数
1
解决办法
2万
查看次数

python-click:另一个选项的依赖选项

这个问题是关于click包的:我想设置我的命令,以便某些命令optional options依赖于特定的选项值,并且根据其值需要。

所需选项:

  1. 输入(输入文件)
  2. doe(整数,代表算法名称)

子选项: 如果是

  1. 等于1然后选项 generator_string应该变成required=True
  2. 等于2然后选项 number_of_sample_points应该变成required=True
  3. 等于3然后选项 number_of_center_points应该变成required=True

有效示例:

  1. --input ./input.txt --doe 1 --generator_string 1234
  2. --input ./input.txt --doe 2 --number_of_sample_points 3
  3. --input ./input.txt --doe 3 --number_of_center_points 2

代码:

import click


def check_output(ctx, param, value):
    if value == 1:
        if not ctx.params['generator_string']:
            setOptionAsRequired(ctx, 'generator_string')
    return value


def setOptionAsRequired(ctx, name):
    for p in ctx.command.params:
        if isinstance(p, click.Option) and …
Run Code Online (Sandbox Code Playgroud)

python command-line-interface python-click

6
推荐指数
1
解决办法
4313
查看次数

jquery滑动侧栏从左到右

我正在尝试创建一个具有类似效果的滑动侧栏

  1. www.wookmark.com
  2. http://www.dynamicdrive.com/dynamicindex1/slideinmenu.htm.

这是我写代码的距离.但这是生涩的.

  1. 任何人都可以提出更好的解决方案与aniamtions/easing/toggle等
  2. 我希望代码独立于左参数,即$("#slide").css("left"," - 150px"); 它应该能够以各种div宽度滑入/滑出

有任何想法吗 ?

CSS

#slide{
border:1.5px solid black;
position:absolute;
top:0;
left:0;
width:150px;
height:100%;
background-color:#F2F2F2;
layer-background-color:#F2F2F2;
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div id="slide" style="left: -150px; top: 0px; width: 160px;">
    <p>Something here</p>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的

<script>
    jQuery(document).ready(function() {
        $('#slide').mouseover(function() {
            $("#slide").css("left", "0px");
        });

        $('#slide').mouseout(function() {
            $("#slide").css("left", "-150px");
        });

    });
 </script>
Run Code Online (Sandbox Code Playgroud)

html jquery sidebar slidetoggle

5
推荐指数
1
解决办法
2万
查看次数

Bootstrap同位素和lazyload通过json获取/加载图像

ajax取出的正常同位素使用正在起作用.看工作jsfiddle.

同位素与懒惰通过ajax取不起作用.看问题jsfiddle.

问题: lazyload不会触发并继续显示灰色图像.

用于lazyload设置的javaScript:

$(document).ready(function () {
    //
    // initialize at ready ;
    //
    $container.isotope({
        itemSelector: '.box',
        columnWidth: function (containerWidth) {
            return containerWidth / 12;
        },
        onLayout: function () {
            $win.trigger("scroll");
        }
    });
    //
    // here i will be using data through api
    // For now I am defining json manually
    // var json is defined at top of this code 
    // considering json return was success
    //$.getJSON(APIURL, function (json) {
    var newElements = ""; …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-isotope jquery-lazyload

5
推荐指数
1
解决办法
2610
查看次数

bind('resize')与.resize()之间的jquery区别

  1. $(window).bind('resize')和之间有什么区别$(window).resize()
  2. 我看到bind嵌套的地方resize.它有什么影响?见下面的代码.
  3. 我知道.resize()关于元素和窗口的工作.是否也bind以类似的方式工作......喜欢$('#el').bind('resize', function (event) { // stuff });

JS:

$(window).bind('resize', function (event) {
    $(window).resize(function () {
         // do something here
    });
});
Run Code Online (Sandbox Code Playgroud)

jquery

5
推荐指数
1
解决办法
5275
查看次数

jQuery名称空间声明和模块化方法

我对如何继续我的项目感到困惑.我正在开发一个企业应用程序,其中要编写许多模块.大多数模块将使用大量的jQuery插件来创建复杂的网格,为不同的目的绘制图形,这意味着模块将向DOM添加div,表等.

我想保留命名空间,因为这将是大型应用程序.为此,我遇到了原型方法自动执行的匿名函数.自动执行匿名函数似乎被推荐了很多.

我的问题是

  1. 自执行函数是否可重用?我的意思是这些是立即执行的,所以假设模块为给定的JSON文件绘制一个复杂的网格.那么我是否可以像jQuery插件一样为3个不同的JSON文件使用相同的自执行匿名函数?
  2. 当写入大量模块时,它们将在启动时自行执行.它会影响Ram/Processor的使用吗?难道不应该在需要时调用模块吗?自我执行有何意义?

我的项目范围:

请帮助我理解我的项目范围中的这个自我执行的东西,这是我的项目持有一个主命名空间说"Myapp",其模块如Myapp.moduleA,Myapp.moduleB.MyApp将触发其模块点击等. 什么是最好的方式去找我?

自我执行匿名函数

(function( skillet, $, undefined ) {
    //Private Property
    var isHot = true;

    //Public Property
    skillet.somevar = "Bacon Strips";

    //Public Method
    skillet.draw = function() {
        //Draw a grid
    };

    //Private Method
    function _grid(  ) {
        //
        }
    }   
}( window.skillet = window.skillet || {}, jQuery ));
Run Code Online (Sandbox Code Playgroud)

javascript jquery

5
推荐指数
1
解决办法
715
查看次数

jQuery 只在主表中选择 tr,而不是在嵌套表中

我正在尝试捕获对表行的点击但我只想捕获主/主表行。如果行再次有表,我想忽略它们。我正在寻找与 .on() 一起使用的选择器,并且只选择主表行而不是嵌套表行。

要求:

  1. 表有动态行,所以我正在寻找解决方案 .on()
  2. 解决方案选择器必须是通用的,我不想使用 tr.odd 或 tr.even 类限制

JSFIDDLE: https ://jsfiddle.net/bababalcksheep/8vpg6dp6/9/

JS:

$(document).ready(function() {
  //'tbody > tr:first:parent tr
  $('#example').on('click', 'tbody > tr', function(e) {
    console.log(this);
    //do something with row in master table
  });
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<table width="100%" cellspacing="0" class="display dataTable no-footer" id="example" role="grid" aria-describedby="example_info" style="width: 100%;">
  <thead>
    <tr role="row">
      <th class="sorting_asc" tabindex="0" aria-controls="example" rowspan="1" colspan="1" style="width: 84px;" aria-sort="ascending" aria-label="Name: activate to sort column descending">Name</th>
      <th class="sorting" tabindex="0" aria-controls="example" rowspan="1" colspan="1" style="width: 124px;" aria-label="Position: activate to sort column …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

5
推荐指数
1
解决办法
2183
查看次数

电子拖放桌面上的远程文件

目的:

使用Electron原生文件拖放将远程文件从电子应用程序中拖出到操作系统的世界中,例如在桌面或某些打开的文件夹上

做法:

渲染

在渲染器中,使用 ipcRenderer.send('ondragstart', url_to_download)

主要过程

在主要过程中,在 ipcMain.on('ondragstart'

  1. 首先下载远程文件并等待它完成
  2. 然后使用event.sender.startDrag(和as文件提供下载文件的os路径

码:

  1. https://github.com/mafar/electron-drag-drop-remote-files
  2. 下载回购然后 npm install && npm start
  3. main.js并且renderer.js是具有逻辑的文件

问题:

  1. 用户想要拖动远程项目并将其放在os桌面上
  2. 用户必须按住鼠标左键并在os桌面上放下时不释放它,直到出现dragicon
  3. 因为dragicon需要时间直到文件下载并可用于删除
  4. 如果您在桌面上快速拖放尚未下载的文件,则本机操作系统不会执行任何操作
  5. 这使得它几乎没用

有什么建议 ?

javascript node.js electron

5
推荐指数
0
解决办法
551
查看次数

python-click:格式化帮助文本

这个问题是关于点击包的:

  1. 帮助的长文本未按预期显示。
  2. /b也尝试过使用,但似乎影响不大。
  3. cmdpowershell相同的代码有不同的结果,为什么?

问题的屏幕截图

代码:

import click


def command_required_option_from_option(require_name, require_map):

    class CommandOptionRequiredClass(click.Command):

        def invoke(self, ctx):
            require = ctx.params[require_name]
            if require not in require_map:
                raise click.ClickException(
                    "Unexpected value for --'{}': {}".format(
                        require_name, require))
            if ctx.params[require_map[require]] is None:
                raise click.ClickException(
                    "With {}={} must specify option --{}".format(
                        require_name, require, require_map[require]))
            super(CommandOptionRequiredClass, self).invoke(ctx)

    return CommandOptionRequiredClass

required_options = {
    1: 'gs',  # generator_string
    2: 'nosp',  # number_of_sample_points
    3: 'nocp',  # number_of_center_points
}


@click.command(context_settings=dict(max_content_width=800), cls=command_required_option_from_option('doe', required_options))
@click.option('--input', required=True, type=click.Path(exists=True), metavar='FILE', …
Run Code Online (Sandbox Code Playgroud)

python command-line-interface python-click

5
推荐指数
1
解决办法
6848
查看次数