小编Mat*_*ain的帖子

如何在NodeJS中拆分和修改字符串?

我有一个字符串:

var str = "123, 124, 234,252";
Run Code Online (Sandbox Code Playgroud)

我想在拆分和增加1后解析每个项目.所以我将:

var arr = [124, 125, 235, 253 ];
Run Code Online (Sandbox Code Playgroud)

我怎么能在NodeJS中做到这一点?

javascript node.js

50
推荐指数
1
解决办法
17万
查看次数

跨域iframe通信

我在页面上创建了一个iframe,并且页面的域名被明确设置为"xyz.com",但iframe的域名默认为"dev.xyz.com",这是我正在开发的实际域名.

问题是,当我尝试通过iframe.contentWindow.document访问iframe时,由于域的不同而失败.

我已经尝试将iframe的src设置为一个带有document.domain ='xyz.com'的文件,但这似乎没有做到这一点......

有任何想法吗?

javascript iframe cross-domain

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

jQuery移动活动指示器未显示在android中

我尝试在我的应用程序中显示活动指示器.我activity.js用于活动指标.那个在浏览器和iPhone上工作得很好但是它不适用于Android设备.

我不知道为什么指标在Android设备中不起作用.

以下是我的活动指标示例代码:

function showIndicator() {
    console.log("inside show indicator");
    applyOverLay();
    var showIndicator = document.createElement("div");
    showIndicator.setAttribute("class", "activity-indicator");
    document.body.appendChild(showIndicator);
    $('.activity-indicator').activity({
        width: 5,
        space: 1,
        length: 3,
        color: '#fff'
    });
}

function applyOverLay() {
    var overlay = document.createElement("div");
    overlay.setAttribute("id", "overlayAttr");
    overlay.setAttribute("class", "overlay");
    document.body.appendChild(overlay);
}

function hideindicator() {
    $('.activity-indicator').activity(false);
    setTimeout(function() { $(".activity-indicator").empty().remove(); }, 0);
    setTimeout(function() { $(".overlay").empty().remove(); }, 0);
}

function loadhtmlpage() {   
    //location.href='#refillReminder';
    $.mobile.changePage("#refillReminder"); 
    showIndicator();
    hideindicator();
}

style.css:

.activity-indicator {
    padding: 10px;
    position: absolute;
    top: 50%;
    left: 45%;
    z-index: 1001;
}
Run Code Online (Sandbox Code Playgroud)

javascript android jquery-mobile cordova

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

Chrome的垃圾收集工作方式有何不同?

当我尝试调试此代码时(http://jsfiddle.net/QWFGN/)

var foo = (function(numb) {
    return {
        bar: function() {
            debugger;
            return "something";
        }
    }
})(1);
foo.bar()
Run Code Online (Sandbox Code Playgroud)

Chrome中的开发人员工具与Firefox中的Firebug和IE中的开发人员工具的行为不同.问题是,变量numb 是不是在Chrome开发者工具可见debugger;线.但是,它在Firebug和IE中可见.如果我尝试输入numbChrome的控制台,我会得到:

ReferenceError: numb is not defined
Run Code Online (Sandbox Code Playgroud)

numb当然,在这个闭包中可以看到,如果我将代码更改为(http://jsfiddle.net/QWFGN/1/)

var foo = (function(numb) {
    return {
        bar: function() {
            debugger;
            console.log(numb);
            return "something";
        }
    }
})(1);
foo.bar()
Run Code Online (Sandbox Code Playgroud)

numb现在也可以在Chrome中看到,我可以获得价值1作为回应.

所以,我的问题是:为什么只有谷歌浏览器看不到从未使用的闭包变量?Google Chrome是否拥有自己的垃圾收集实现,或者仅与Google Chrome中的调试工具实施相关.

javascript garbage-collection google-chrome v8

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

如何检查插座是否仍然连接?

我有一个用户使用socket.io连接到我的节点服务器的页面,但我只允许他们有一个打开的socket.io连接到服务器(通过在授权它们并将其存储在一个数组中时传递他们的帐户ID)和99%的情况下这很好用.问题是,有时当用户断开连接时,服务器端断开连接事件由于某种原因不会触发,因此我无法从客户端阵列中清除他们的帐户,最终导致他们被锁定.

有没有办法让我检查他们的旧套接字连接(我的ID是否仍然有效)?(所以,如果不是,我可以清除他们的旧连接,让他们再次连接)

node.js socket.io

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

使用安全组件进行CakePHP控制器测试

考虑以下代码:

控制器代码

<?php
App::uses('AppController', 'Controller');

class UsersController extends AppController {

    public $components = array(
        'Security',
        'Session'
    );

    public function example() {
        if ($this->request->is('post')) {
            $this->set('some_var', true);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

查看代码

<?php

echo $this->Form->create();
echo $this->Form->input('name');
echo $this->Form->end('Submit');
Run Code Online (Sandbox Code Playgroud)

由于我有安全组件,以任何方式篡改表单(例如向其添加字段)将导致请求被黑洞.我想测试一下:

测试代码

<?php

class UsersControllerTest extends ControllerTestCase {

    public function testExamplePostValidData() {
        $this->Controller = $this->generate('Users', array(
            'components' => array(
                'Security'
            )
        ));

        $data = array(
            'User' => array(
                'name' => 'John Doe'
            )
        );

        $this->testAction('/users/example', array('data' => $data, 'method' => 'post'));
        $this->assertTrue($this->vars['some_var']);
    } …
Run Code Online (Sandbox Code Playgroud)

testing cakephp

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

如何增加codeigniter验证码助手的字体大小

我正在使用codeigniter*capctha*帮助器.事情是我不能增加字母的字体大小.我试着这样做

if ($use_font == FALSE)
{
    $font_size = 6;
    $x = rand(0, $img_width/($length/2));
    $y = 0;
}
else
{
    $font_size = 20;
    $x = rand(0, $img_width/($length/1.5));
    $y = $font_size+2;
}
Run Code Online (Sandbox Code Playgroud)

但没有任何反应,如何改变字体大小,请帮忙.提前致谢.

php captcha codeigniter helper

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

更新TStringList名称/值对中的名称值

是否可以更新特定TStringList名称/值对的Name字符串?

List.Names[I]:= name;
Run Code Online (Sandbox Code Playgroud)

我知道Names是一个只读属性,我想知道是否有另一种我不知道的方式?

或者我必须对整个字符串进行整个更新

List[I]:= name=value
Run Code Online (Sandbox Code Playgroud)

问题是我在名称/值对的值部分存储了大量的字符串值

name=value1,value2,value3,value4,value5,value6,value7,value8,value9,value10
Run Code Online (Sandbox Code Playgroud)

我宁愿只更新名称部分9因为这就是我需要做的全部)

谢谢

delphi delphi-2010

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

页脚的内容似乎不起作用

我正在尝试在phantomjs示例中创建自定义页脚:https://github.com/ariya/phantomjs/blob/master/examples/printheaderfooter.js

这是我的代码:

var phantom = require('node-phantom');

phantom.create(function (err, ph) {
    ph.createPage(function (err, page) {
         page.set('paperSize', {
              format: 'A4',
              orientation: 'portrait',
              footer: {
                contents: ph.callback(function (pageNum, numPages) {
                  if (pageNum == 1) {
                    return "";
                  }
                  return "<h1>Header <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>";
                })
              }
         }, function () {
             page.open('http://www.google.com', function () {
              })
         })
    })
});
Run Code Online (Sandbox Code Playgroud)

但不幸的是我收到以下错误:

TypeError: Object #<Object> has no method 'callback';
Run Code Online (Sandbox Code Playgroud)

是不是ph不暴露回调方法的错误?

node.js phantomjs

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

Php Date功能在实时服务器中不起作用

我使用低于日期功能在localhost中使用php显示当前日期和时间

<?php
echo date('Y-m-d H:i:s');
?>
Run Code Online (Sandbox Code Playgroud)

并显示输出为2013-06-24 14:45:13 但当我在实时服务器上运行上面的PHP代码时,它显示输出为2013-06-24 06:47:28.所以,任何人都告诉如何在实时服务器中以24小时格式显示日期和时间..

php date

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

如何在node.js中找到"{}"之间的匹配字符串

我的示例字符串是

var str = "My name is {name}.from {area}";
Run Code Online (Sandbox Code Playgroud)

我需要与该字符串分开{name}和{area}.

我试过了

var s = "My name is {name}.from {area}";
var matches = s.match(/\{(.*?)\}/);
console.log(matches);
Run Code Online (Sandbox Code Playgroud)

它只给出了第一次出现.如何获取字符串{name} {area}.

javascript regex node.js

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

CSS条件语句

我知道这对于css条件格式化是可能的:

<!--[if !IE]>
   link/css style goes here
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

但是有可能在那里有OR语句吗?如:

<!--[if !IE or !Opera]>
    link/css style goes here
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

提前致谢!

html css

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

获取使用但未附加到页面的图像?

我想获得页面中使用的所有图像.这是我正在使用的代码:

function get_page_images($id) {
    $photos = get_children( array(
        'post_parent' => $id,
        'post_status' => 'inherit',
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'order' => 'ASC',
        'orderby' => 'menu_order ID') );

    $results = array();

    if ($photos) {
        foreach ($photos as $photo) {
            // get the correct image html for the selected size
            $results[] = wp_get_attachment_image($photo->ID, $size);
        }
    }

    return $results;
}
Run Code Online (Sandbox Code Playgroud)

这只会获取专门为此页面上传的图片,如果我重新使用之前已经上传过的图片用于不同的页面/帖子,则不会检索这些图片(因为它们附加到他们上传到的帖子,但不是任何帖子它们被重复使用).有没有人知道如何获取页面/帖子中使用的所有图像?

wordpress

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