我正在为jQuery编写一个插件,我需要向服务器发送一小段数据,但我需要设置我发送的json对象的var名称:
var params = {name:'var_name'}
$.post('page.php', {params.name:'the value'}, function () { /* etc. */ });
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我想load
,edit
并save
用一记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) 如果我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) 我正在一个用户可以选择他的国家的网站上工作,现在我已经创建了一个包含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
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) javascript ×2
jquery ×2
optimization ×2
php ×2
arrays ×1
benchmarking ×1
cakephp-2.0 ×1
save ×1