小编vit*_*tto的帖子

如何在JavaScript中使用字符串设置对象参数名称?

我正在为jQuery编写一个插件,我需要向服务器发送一小段数据,但我需要设置我发送的json对象的var名称:

var params = {name:'var_name'}
$.post('page.php', {params.name:'the value'}, function () { /* etc. */ });
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

javascript jquery

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

使用cakephp保存数据不起作用

我想load,editsave用一记CakePHP 2.0,但我得到generic error 的期间save不帮我明白问题出在哪里方法.

如果我尝试debug($this->User->invalidFields());我得到一个empty array,但我false$this->User->save()条件得到.

这是我得到错误的控制器操作:

public function activate ($code = false) {
    if (!empty ($code)) {

        // if I printr $user I get the right user
        $user = $this->User->find('first', array('activation_key' => $code));

        if (!empty($user)) {
            $this->User->set(array (
                'activation_key' => null,
                'active' => 1
            ));

            if ($this->User->save()) {
                $this->render('activation_successful');
            } else {
                // I get this error
                $this->set('status', 'Save error …
Run Code Online (Sandbox Code Playgroud)

error-handling save cakephp-2.0

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

使用jQuery获取html元素的宽度百分比%

如果我alert其中有一个CSS选择器设置为元素width:100%,我得到它在px,是有一些方法来得到它%从CSS设置,我需要它来修复一些脚本流体布局.

// css
.my-element {
    width:100%;
}

// javascript
alert('width: '+$('.my-element').css('width'));
// this alerts "width: 1116px" instead of "width: 100%"
Run Code Online (Sandbox Code Playgroud)

也许这样的事情总是如此?

alert($('.my-element').outerWidth() == $('.my-element').parent().outerWidth());
Run Code Online (Sandbox Code Playgroud)

javascript jquery

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

世界各国在一个PHP阵列上,如果静态更好?

我正在一个用户可以选择他的国家的网站上工作,现在我已经创建了一个包含alla国家名称和相关代码的数组,例如意大利的代码:

<?php
$nations[] = array ("code" => "af", "name" => "Afghanistan");
$nations[] = array ("code" => "ax", "name" => "Aland Islands");
$nations[] = array ("code" => "al", "name" => "Albania");
$nations[] = array ("code" => "dz", "name" => "Algeria");
$nations[] = array ("code" => "as", "name" => "American Samoa");
$nations[] = array ("code" => "ad", "name" => "Andorra");
$nations[] = array ("code" => "ao", "name" => "Angola");
$nations[] = array ("code" => "ai", "name" => "Anguilla");
$nations[] = array ("code" …
Run Code Online (Sandbox Code Playgroud)

php arrays optimization

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

在PHP中从if语句或从数组中获取值更快?

也许这是一个愚蠢的问题,但更快的是什么?

<?php

function getCss1 ($id = 0) {
    if ($id == 1) {
        return 'red';
    } else if ($id == 2) {
        return 'yellow';
    } else if ($id == 3) {
        return 'green';
    } else if ($id == 4) {
        return 'blue';
    } else if ($id == 5) {
        return 'orange';
    } else {
        return 'grey';
    }
}

function getCss2 ($id = 0) {
    $css[] = 'grey';
    $css[] = 'red';
    $css[] = 'yellow';
    $css[] = 'green';
    $css[] = 'blue';
    $css[] …
Run Code Online (Sandbox Code Playgroud)

php optimization benchmarking

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