小编bob*_*obb的帖子

在循环中绑定事件处理程序需要关闭吗?

我正在尝试在循环中绑定事件处理程序,例如:

        var tabs = ['one', 'two', 'three', 'four']

        for(var i = 0; i < tabs.length; i++) {
            alert(tabs[i]);
            var id = i;
            $('#' + tabs[i]).bind('click', function() {
               loadTabs(id, tabs);
            });
        }
Run Code Online (Sandbox Code Playgroud)

只保留最后一个绑定(值'四').

我正在尝试整合当前可行的代码:

        $('#one').click(function() {
            loadTabs(0, tabs);
        });

        $('#two').click(function() {
            loadTabs(1, tabs);
        });

        $('#three').click(function() {
            loadTabs(2, tabs);
        });

        $('#four').click(function() {
            loadTabs(3, tabs);
        });
Run Code Online (Sandbox Code Playgroud)

以为我可能需要关闭此帖子.

javascript jquery closures bind

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

在页面URL中强制执行slug?

我正在决定是否强制要求slu to才能查看提交内容.

现在,要么提交提交中的任何一个:

domain.com/category/id/1/slug-title-here

domain.com/category/id/1/slug-blah-foo-bar

domain.com/category/id/1/

所有人都去了同一个提交.

您也可以将slug更改为您想要的任何内容,它仍然可以工作,因为它只检查类别,ID和提交#(在第二个示例中).

我想知道这是否是正确的方法呢?从SEO的角度来看,我应该这样做吗?如果没有,我应该对没有slug请求URL的用户做什么?

php url seo cakephp slug

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

鼠标滚轮事件检测目前无法在Firefox中使用

出于某种原因,我在尝试识别Firefox中的鼠标滚轮事件时遇到了麻烦.这适用于IE,Chrome,Safari,Opera,但不适用于FF.我在DOMMouseScroll上附加了一个事件监听器,应该在FF中识别.

小提琴演示

$(document).unbind('mousewheel DOMMouseScroll').on('mousewheel DOMMouseScroll', function(e) {
    var evt = event || e || window.event;
    var delta = evt.detail < 0 || evt.wheelDelta > 0 ? 1 : -1;

    if (delta < 0) {
        // scroll down
    } else {
        // scroll up
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery mousewheel

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

无法在 Google Cloud SQL 上创建 postgis 扩展

我有一个在 Google Cloud SQL 上创建的 Postgres 数据库和用户。

我正在尝试为该用户安装 postgis 扩展:

myuser=> CREATE EXTENSION postgis;
ERROR:  permission denied to create extension "postgis"
HINT:  Must be superuser to create this extension.
Run Code Online (Sandbox Code Playgroud)

如您所见,它不允许我为该用户创建扩展,因此我尝试使该用户成为该postgres角色的超级用户:

postgres=> ALTER USER myuser WITH SUPERUSER;
ERROR:  must be superuser to alter superusers
Run Code Online (Sandbox Code Playgroud)

我收到以下错误。这是因为 Google Cloud SQL 不允许SUPERUSER任何 postgres 帐户使用该角色: https: //cloud.google.com/sql/docs/postgres/users

所以我处于这种奇怪的炼狱状态,我需要添加这个扩展,但不能。

有关如何进行的任何提示?

postgresql google-cloud-sql google-cloud-platform

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

看看 div 是否包含另一个具有特定类的 div ?

假设我有:

<div class="outer">

<div class="foo bar"></div>

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

如何检查$('.outer')div 中是否有名为“bar”的类?

css jquery

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

jQuery粘贴输入的URL验证

我正在尝试确定粘贴的网址是否有效.我正在使用bind()函数来检测粘贴事件.我正在使用我在这里找到的正则表达式进行验证(其工作正常并且很好).我还附加一些文字告诉用户它是否是有效网址.

当它在bind()中时唯一不起作用的是URL验证.但是当它放在它外面时它可以工作.

JS:

 function validateURL(textval) {
  var urlregex = new RegExp( "^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&amp;%\$#\=~_\-]+))*$");
  return urlregex.test(textval);
}

$(document).ready(function(){   

    // assign whatever is in the inputbox to a variable
    var url = $("#ent").val()

    //this is if they paste the url from somewhere
    $("#ent").bind('paste', function() {

        if(validateURL(url)) {
            $("#ent").css("background-color","green");
            $("#status").append("Valid URL");
            $("#submit").attr('disabled', 'disabled');
        }
    });

});
Run Code Online (Sandbox Code Playgroud)

HTML:

<input type="text" name="ent" id="ent">
<input type="submit" name="submit" id="submit">
<div id="status"></div>
Run Code Online (Sandbox Code Playgroud)

javascript validation jquery paste

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

Javascript替换`sq -`或`sq

我想对包含的字符串进行替换,sq-或者sq.我正在考虑做这样的事情:

var imgSrc = event.dataTransfer.getData('Text');
    imgSrc = imgSrc.replace('sq-', 'mt-') || imgSrc.replace('sq.', 'mt.');
Run Code Online (Sandbox Code Playgroud)

关于如何让这个工作的任何想法?

javascript regex replace

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

想要将变量传递给node async的map方法

我正在使用节点异步,我想将变量传递给它在第二个参数中使用的方法...例如:

  async.map(submissions, addScore, function(err, submissions) {
    if (submissions) {
      return submissions;
    }
  });
Run Code Online (Sandbox Code Playgroud)

我想通过userId沿addScore,但我不知道如何做到这一点.

addScore是我的方法,我呼吁每次提交,它需要一个userId.

javascript asynchronous function node.js

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

如何在jQuery中为字符串添加fadeIn效果?

我有以下字符串,增加段落中包含的整数,并且我想将fadeIn()jQuery函数附加到它.我试图将它连接到字符串的末尾,但这不起作用.关于该做什么的任何建议?

                $p.text(parseInt($p.text(),10) + 1);
Run Code Online (Sandbox Code Playgroud)

javascript jquery fadein

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

如何在jQuery中回显PHP?

我正在尝试在我的一个jQuery函数中使用我的一个PHP函数.我知道它不会执行代码,但我需要回显函数调用,因此服务器可以处理它.到目前为止我有这个:

    .html('<h2>Please <a href=""<?php echo absolute_url("login.php"); ?>"">login</a> or <a href="signup.php">register</a> to vote for this post.</h2>(click on this box to close)')
Run Code Online (Sandbox Code Playgroud)

但它无法正常工作.我听说我需要在Javascript中用引号括起实际的php函数调用,我做了(单个和双重),但他们没有做到这一点.有任何想法吗?

任何想知道的人的整个功能:

      // login or register notification
$(document).ready(function() {
    $('.notice').click(function() {
        $('.error-notification').remove();
        var $err = $('<div>').addClass('error-notification')
        .html('<h2>Please <a href=""<?php echo absolute_url("login.php"); ?>"">login</a> or <a href="signup.php">register</a> to vote for this post.</h2>(click on this box to close)')
        .css('left', $(this).position().left);
        $(this).after($err);
        $err.fadeIn(150);
    });
    $('.error-notification').live('click', function() {
        $(this).fadeOut(150, function() {
            $(this).remove();
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript php jquery echo

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

用户验证通过用户模型在CakePHP中无法正常工作

出于某种原因,我不能按照我的意愿使用此验证,特别是使用密码minLength字段.

其他一切都很好(甚至用户名的minLength工作).出于某种原因,当我在密码字段中添加相同的minLength规则时,它只是忽略它,当我实际输入密码时,它告诉我需要输入密码:

    var $validate = array(
'email' => array(
    'email' => array(
        'rule' => array('email', true),
        'required' => true,
        'allowEmpty' => false,
        'message' => 'Please enter a valid email address'
    ),
    'isUnique' => array(
        'rule' => 'isUnique',
        'message' => 'This email is already in use'
    )
),
'username' => array(
    'notEmpty' => array(
        'rule' => 'notEmpty',
        'required' => true,
        'message' => 'Please enter a valid username'
    ),
    'allowedCharacters' => array(
        'rule' => '/^[a-zA-Z]+[0-9]*$/',
        'message' => 'Please enter a valid username' …
Run Code Online (Sandbox Code Playgroud)

php cakephp model cakephp-1.3

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