小编Zac*_*olf的帖子

jQuery .trigger()多个事件

我正在编写一个jQuery插件并使用.on.trigger作为我的pub/sub系统.但是,我想在不同的场景中触发多个事件.

这可能是一个字符串,就像.on方法一样吗?

目标:

$this.trigger("success next etc");    // doesn't work
Run Code Online (Sandbox Code Playgroud)

当前解决方案

$this
    .trigger("success")
    .trigger("next")
    .trigger("etc");                  // works, triggers all three events
Run Code Online (Sandbox Code Playgroud)

有什么建议?

javascript jquery triggers

23
推荐指数
3
解决办法
2万
查看次数

jQuery选择器在ajax的解析HTML中表现不尽如人意

我今天遇到了一个奇怪的问题,我希望别人可以帮我解决这个问题.

我正在进行的项目或多或少是一个jQuery幻灯片.我有一个超级简单的文件,我正在加载测试一切,它看起来像这样:

<!doctype html public "(?°?°??? ???">
    <html>
        <head>
            <meta charset="utf-8">
            <title>test</title>
        </head>
        <body>
            <div id="slides" data-slidesShow="holder">
                <div class="slide" id="test1">test div 1</div>
                <div class="slide" id="test2">test div 2</div>
                <div class="slide" id="test3">test div 3</div>
            </div>

            <button id="previous">previous</button>
            <button id="next">next</button>

            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
            <script>window.jQuery || document.write('<script src="js/libs/jquery-1.7.2.min.js"><\/script>')</script>

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

            <?php include 'footer.php'; ?>
        </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

再说一遍,这里甚至没有任何东西.

现在,在jQuery中,我正在获取并解析页面,如:

$.ajax({
    url:      target.path,
    dataType: "html",
    complete: function(data){
        var $slides     =   $('[data-slidesShow="holder"]', $(data.responseText));

        console.log($slides); // returns []
    }
});
Run Code Online (Sandbox Code Playgroud)

但!$ slides返回一个空数组,除非我将它包装在一个无意义的div中,例如:

<div class="stupid-wraper-div-that-i-dont-want-or-need">
    <div id="slides" data-slidesShow="holder">
        <div …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery jquery-plugins jquery-selectors

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

如何使用第三方.flow文件?

我正在努力将添加到React.js应用程序.我使用flow-typed来添加几个包,这似乎是有效的.

这个问题是我使用的是Material-UI测试版.他们没有流式输入的回购,但他们确实提供了Component.js.flow文件.

但是,我收到此错误:

Error: src/NotFound/NotFound.js:6
  6: import Button from 'material-ui/Button'
                        ^^^^^^^^^^^^^^^^^^^^ material-ui/Button. Required module not found

Error: src/NotFound/NotFound.js:8
  8: import { withStyles } from 'material-ui/styles'
                                ^^^^^^^^^^^^^^^^^^^^ material-ui/styles. Required module not found
Run Code Online (Sandbox Code Playgroud)

我的.flowconfig:

[ignore]
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/build/.*
<PROJECT_ROOT>/scripts/.*
<PROJECT_ROOT>/coverage/.*
<PROJECT_ROOT>/config/.*
.*\.test\.js

[include]

[libs]
<PROJECT_ROOT>/flow-typed/.*

[lints]

[options]
emoji=true
Run Code Online (Sandbox Code Playgroud)

我在支持论坛中尝试了几种解决方案,但我仍然不了解如何连接它.

重要包装版本:

react@15.5.4
material-ui@1.0.0-beta.8
flow-bin@0.54.0
Run Code Online (Sandbox Code Playgroud)

javascript reactjs flowtype

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

与imagepng的PHP问题显示损坏的图像

我正在尝试创建一个动态图像生成器,它也可以缓存图像.

一切都很完美,除了由于某种原因我保存图像并尝试同时显示它时,它显示了一个破碎的图像图标(如:http://cl.ly/image/3K1f0R0n1R0U).

代码示例:

// some string parsing junk happens up here, but removing that didn't change 
// what I've been having a problem with

header("Content-type: image/png;");

if(file_exists($fullFileName)){ // serve the file if it already exists
    ob_clean();
    flush();
    readfile($fullFileName);
    exit;
} else { // create the file if it doesn't exist
    $my_img = imagecreate(200, 80);
    $background = imagecolorallocatealpha($my_img, 0, 0, 0, 127);
    $line_colour = imagecolorallocatealpha($my_img, $color["r"], $color["g"], $color["b"], $color["a"]);

    imagesetthickness($my_img, 1);
    imageline($my_img, 30, 45, 165, 45, $line_colour); …
Run Code Online (Sandbox Code Playgroud)

php broken-image

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