小编HP.*_*HP.的帖子

插件,以避免Wordpress中的共享用户名

有没有办法让Wordpress无效共享用户名(基于IP地址或在不同位置同时登录)?如果有一个插件只是为了跟踪IP地址和登录时间,它也应该没问题.谢谢

html php wordpress

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

casper.js中的setInterval和this.wait

我需要在每次迭代之间进行3次和2次循环.我试过这3个选项:

选项1

var casper = require('casper').create({
    verbose: false,
    logLevel: 'debug'
});

casper.start("http://google.com");

casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
})

casper.thenEvaluate(function() {
    var x = 0;
    var intervalID = setInterval(function () {

       console.log("Using setInternal " + x);

       if (++x === 3) {
           window.clearInterval(intervalID);
       }
    }, 2000);

});

casper.run();
Run Code Online (Sandbox Code Playgroud)

观察:没有出现因为剧本在第一次setInterval被调用之前立即结束.

选项2

替换thenEvaluate()then()下面

for (i=0; i<3; i++) {
    this.wait(2000);
    this.echo('Using this.wait ' + i);
}
Run Code Online (Sandbox Code Playgroud)

观察:它立即输出3次,然后等待很长时间,因为this.wait()是异步.这不是我想要的,因为我想在两者之间延迟. …

javascript webkit qtwebkit phantomjs casperjs

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

Angularjs指令在textarea插入符号中插入文本

我有控制器MyCtrl和指令myText.当模型中的MyCtrl变化,我想更新textareamyText插入在当前位置/插入符文本指令.

我试图重用这个插入文本的代码,其中游标使用Javascript/jquery

我的代码:http://plnkr.co/edit/WfucIVbls2eekL8kUp7e

这是我的HTML:

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="style.css" rel="stylesheet" />
    <script data-semver="1.2.10" src="http://code.angularjs.org/1.2.10/angular.js" data-require="angular.js@1.2.x"></script>
    <script src="app.js"></script>
  </head>

  <body>
    <div ng-controller="MyCtrl">
      <input ng-model="someInput">
      <button ng-click="add()">Add</button>
      <p ng-repeat="item in items">Created {{ item }}</p>  
    </div>

    <textarea my-text="">

    </textarea>

  </body>

</html>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var app = angular.module('plunker', []);

app.controller('MyCtrl', function($scope, $rootScope) {
  $scope.items = …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery dom angularjs

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

匹配所有GET url使用角度模拟后端

我现在正在写一个没有后端ajax的前端.我angular-mocks用来模拟这样的API调用:

$httpBackend.when('GET', '/somelink').respond(function(method, url, data) {
  //do something
});
Run Code Online (Sandbox Code Playgroud)

但是,如果ajax通过params: {id:12345},它将附加到url '/somelink?id=12345'.这并不赶上when('GET', '/somelink')

有没有办法使用RegEx或一些技巧来解决这个问题?只是为了不管里面是什么params,respond()仍然被称为?

谢谢.

更新1:

我不能使用.whenGET,因为我的backendless系统POSTPUT为好.所以我需要保持它的通用性.这两个参数.when('GET', '/somelink')实际上是我代码中的变量.

由于'/somelink'是另一个变量JSON,因此/\/somelink/在JSON中使用RegEx 似乎不起作用.至少那是我现在看到的.

javascript regex ajax angularjs angular-mock

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

jQuery width()函数在Internet Explorer 9中返回错误的值

我之前使用过Easy Slider jQuery插件,直到现在才出现问题.问题很奇怪.看看这个主页 http://bit.ly/HKiWY6

该页面将弹出一个显示两个值的警报:

$("#slider").width()
Run Code Online (Sandbox Code Playgroud)

$("#slider3").width()
Run Code Online (Sandbox Code Playgroud)

我已经在css中设置了两者的值.一个是710px,一个是700px.

如果你在IE9中运行,它会显示默认值$(window).width(),而不是当前窗口或文档宽度.FF和Chrome正确返回.这是为什么?

html javascript css jquery internet-explorer

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

将变量从this.evaluate传递给casper.then

我一定是失去了我的脑海里就这一点,但它为什么没有打印出来"1: Google Search",并"2: Google Search"?基本上:如何在this.evaluate中获取变量并在casper.js范围的其余部分中使用它?

var casper = require("casper").create();
var buttonText;

casper.start("http://google.com");

casper.then(function() {
  buttonText = this.evaluate(function () {
    var myTxt = document.querySelector('#gbqfsa').innerText;
    console.log('1: ' + myTxt);

    return myTxt;
  }); 
});

casper.then(function() {
  this.echo('2: ' + buttonText);
});

casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
});

casper.run();
Run Code Online (Sandbox Code Playgroud)

我在这里使用这些库:

https://github.com/ariya/phantomjs

http://casperjs.org/index.html

javascript scope webkit phantomjs casperjs

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

使用Backbone.js的多个页面

我使用的是Backbone Boilerplate https://github.com/tbranyen/backbone-boilerplate,不知道处理多个页面的最佳方法是什么.我找不到能帮助我轻松理解的答案.基本上,我在考虑这些选择:

  1. 每个页面应该有不同config.js吗?喜欢config-userpage.js,config-homepage.js......?
  2. 我应该router.js为不同的页面改变不同吗?喜欢router-userpage.js或者router-homepage.js......?
  3. 我应该尝试不同的样板,如https://github.com/hbarroso/backbone-boilerplate吗?

javascript node.js backbone.js single-page-application backbone-boilerplate

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

有没有办法将对象传递给casper.js的evaluate()?

我看到了这个帖子,看起来没有办法将复杂的对象传递给evaluate() https://groups.google.com/forum/#!topic/casperjs/x7I8LDFwFJ0

因此,如果我写一个对象并希望分享不同的对象,evaluate()我该怎么做?

让我说一些愚蠢的对象,我想一次又一次地使用getData函数:

var testObj = (function() {
  var a = 1;

  function test1(b) {
    return (a+b);
  }

  return {
    getData : function(arg) {
      return (test1(3) + arg);
    }
  }
})();
Run Code Online (Sandbox Code Playgroud)

有可能的解决方法吗?

更新1:

我的意思是传递带有函数的对象.如下所示但它不起作用(返回null):

var casper = require('casper').create();

casper.start('about:blank', function() {

    var TestObj = function() {
      var a = 1;

      function test1(b) {
        return (a+b);
      }

      return {
        getData : function(arg) {
          return (test1(3) + arg);
        }
      }
    }

    var testObj = new TestObj(); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js web-scraping phantomjs casperjs

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

数据属性中区分大小写

那一定是迟到了,我的大脑麻木了.为什么jQuery不能识别数据属性中的区分大小写?我遇到了这个恼人的问题:

HTML:

<a data-showId="12345">Test 1</a>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

console.log($('a').data('showId'));
console.log($('a').data('showid'));
Run Code Online (Sandbox Code Playgroud)

第一行未定义,第二行正确返回12345.我认为它应该在第一行正确返回,在第二行未定义.那么它是否意味着所有数据都必须是小写的?

在这里查看http://jsfiddle.net/qhoc/7dExt/1/

html javascript jquery custom-data-attribute

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

从Cordova Capture获取base64音频数据

我正在使用ngCordova Capture通过录制音频来编写此代码,并将base64发送到某处(通过REST).我可以让Capture Audio工作但是一旦它返回audioURI,我就无法将文件系统中的数据作为base64.我的代码如下:

$cordovaCapture.captureAudio(options).then(function(audioURI) {
  $scope.post.tracId = $scope.tracId;
  $scope.post.type = 'audio';
  console.log('audioURI:');
  console.log(audioURI);
  var path = audioURI[0].localURL;
  console.log('path:');
  console.log(path);

  window.resolveLocalFileSystemURL(path, function(fileObj) {
    var reader  = new FileReader();
    console.log('fileObj:');
    console.log(fileObj);

    reader.onloadend = function (event) {
      console.log('reader.result:');
      console.log(reader.result);
      console.log('event.result:');
      console.log(event.result);
    }
    reader.onload = function(event2) {
      console.log('event2.result:');
      console.log(event2.target.result);
    };
    reader.readAsDataURL(fileObj);
   console.log(fileObj.filesystem.root.nativeURL + ' ' + fileObj.name);
   $cordovaFile.readAsDataURL(fileObj.filesystem.root.nativeURL, fileObj.name)
   .then(function (success) {
         console.log('success:');
         console.log(success);
         }, function (error) {
         // error
         });
  });
Run Code Online (Sandbox Code Playgroud)

这是控制台日志中的输出:

在此输入图像描述

那么如何从.wav文件中获取base64数据呢?

我一直在阅读这些链接:

PhoneGap FileReader/readAsDataURL不触发回调

https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL

http://jsfiddle.net/eliseosoto/JHQnk/

http://community.phonegap.com/nitobi/topics/filereader_onload_not_working_with_phonegap_build_2_5_0

javascript audio filereader ios cordova

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