$(document).ready(function() {
$('#domain').change(function() {
//
});
});
Run Code Online (Sandbox Code Playgroud)
更改函数内的代码基本上会发送ajax请求来运行PHP脚本.#domain是文本输入字段.基本上我想要做的是在文本字段内的某些文本中将ajax请求作为用户类型发送(例如搜索建议).
但是,我想设置一个时间间隔,以减轻PHP服务器的负载.因为如果每当用户向文本字段添加另一个字母时jQuery发送AJAX请求,它将消耗大量带宽.
所以我想设2秒作为间隔.每次用户键入字母时都会触发AJAX请求,但最大频率为2秒.
我怎样才能做到这一点?
好吧,假设我有一张带照片的桌子.
我想要做的是在页面上显示基于URI中的id的照片.对照片感兴趣我想要附近照片的10张缩略图,当前的照片应该在缩略图的中间.
这是我到目前为止的查询(这只是一个例子,我用7作为id):
SELECT
A.*
FROM
(SELECT
*
FROM media
WHERE id < 7
ORDER BY id DESC
LIMIT 0, 4
UNION
SELECT
*
FROM media
WHERE id >= 7
ORDER BY id ASC
LIMIT 0, 6
) as A
ORDER BY A.id
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
#1221 - Incorrect usage of UNION and ORDER BY
Run Code Online (Sandbox Code Playgroud) 我写了几个自定义视图助手,但我使用它们有点麻烦.如果我在控制器动作中添加辅助路径,如下所示:
public function fooAction()
{
$this->view->addHelperPath('My/View/Helper', 'My_View_Helper');
}
Run Code Online (Sandbox Code Playgroud)
然后我可以毫无问题地使用该路径中的视图.但是当我在bootstrap文件中添加这样的路径时:
protected function _initView()
{
$this->view = new Zend_View();
$this->view->doctype('XHTML1_STRICT');
$this->view->headScript()->appendFile($this->view->baseUrl()
. '/js/jquery-ui/jquery.js');
$this->view->headMeta()->appendHttpEquiv('Content-Type',
'text/html; charset=UTF-8');
$this->view->headMeta()->appendHttpEquiv('Content-Style-Type',
'text/css');
$this->view->headMeta()->appendHttpEquiv('Content-Language', 'sk');
$this->view->headLink()->appendStylesheet($this->view->baseUrl()
. '/css/reset.css');
$this->view->addHelperPath('My/View/Helper', 'My_View_Helper');
}
Run Code Online (Sandbox Code Playgroud)
然后视图助手不起作用.这是为什么?在每个控制器动作中添加路径太麻烦了.以下是我的自定义视图助手的外观示例:
class My_View_Helper_FooBar
{
public function fooBar() {
return 'hello world';
}
}
Run Code Online (Sandbox Code Playgroud)
我在视图中使用它们:
<?php echo $this->fooBar(); ?>
Run Code Online (Sandbox Code Playgroud)
我应该发布我的整个bootstrap文件吗?
更新:
添加完整的bootstrap文件以防万一:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initFrontController()
{
$this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->addModuleDirectory(APPLICATION_PATH
. '/modules');
Zend_Controller_Action_HelperBroker::addPath(
'My/Controller/Action/Helper',
'My_Controller_Action_Helper'
);
$this->frontController->registerPlugin(new My_Controller_Plugin_Auth());
$this->frontController->setBaseUrl('/');
}
protected function …Run Code Online (Sandbox Code Playgroud) 这是我的jquery代码:
$(document).ready(function() {
if ($('#login').length == 0) {
$('#login').css('background', "url('/css/login-bg.gif') 2px center no-repeat");
}
if ($('#password').length == 0) {
$('#password').css('background', "url('/css/password-bg.gif') 2px center no-repeat");
}
$('#login').focus(function() {
$(this).css('background', 'transparent');
});
$('#password').focus(function() {
$(this).css('background', 'transparent');
});
});
Run Code Online (Sandbox Code Playgroud)
它适用于Firefox但不适用于IE7或IE8.为什么?
此代码的目的:它应该在登录表单中显示用户友好的文本,以便用户知道填写用户名和密码输入字段的内容.这很重要,因为输入字段没有标签(我知道......但客户端只是不想要标签).
if($('#selector').length == 0)条件存在,因为如果用户在浏览器中保存他/她的用户名和密码,浏览器将自动填写保存的值,因此它确保了背景图像不重叠他们.
我知道这违反了REST架构,但从实用的角度来看,使用GET请求方法从数据库中删除数据有什么问题?
假设我构建了一个具有管理面板的应用程序.在管理面板中,管理员可以通过访问以下URI来删除项目:
/admin-panel/items-controller/remove-action/id/X
Run Code Online (Sandbox Code Playgroud)
其中X是要删除的项的主键.
使用这种方法有任何实际缺点吗?请教育我,因为我不明白为什么应该使用POST.
使用POST删除数据的主要问题是,不是简单的链接(易于在CSS中设置样式),而是必须在每个项目旁边打印一个带有POST方法的表单,然后将其设置为看起来像一个按钮/链接.还是我完全误会了?
假设这样的HTML标记:
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li><!-- I want to select only this -->
</ul>
Run Code Online (Sandbox Code Playgroud)
是否可以只选择无序列表元素中的第三个列表项?我一直在浏览jQuery文档,但我找不到任何可以做到这一点的选择器.
我需要在具有特定尺寸的新窗口(NOT TAB)中打开某些链接.
这将在新标签中打开一个链接:
$(document).ready(function() {
$('a[rel|=external]').click(function(){
window.open(this.href);
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
要在新窗口中打开链接需要更改什么.
编辑:这是我的整个javascript文件:
$(document).ready(function() {
$('a[rel=external]').click(function(){
window.open(this.href);
return false;
});
$('a[rel=external-new-window]').click(function(){
window.open(this.href, "myWindowName", "width=800, height=600");
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<a href="/clientarea/utils/law/id/2832" rel="external-new-window" class="accessible-link">§5, odsek 2</a>
Run Code Online (Sandbox Code Playgroud) 这是我的阵列:
$arr = array(-3, -4, 1, -1, 2, 4, -2, 3);
Run Code Online (Sandbox Code Playgroud)
我想这样排序:
1
2
3
4
-1
-2
-3
-4
Run Code Online (Sandbox Code Playgroud)
因此,首先会有从最低值到最高值排序的值大于零的值,然后会有从最高值到最低值排序的负值.
有一些优雅的方式来做到这一点?
我在C:\ Python26中安装了Python 2.6.4.
我从这里安装了PyQt4:http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-Py2.6-gpl-4.7.7-1.exe
我已将此路径添加到%PATH%:
C:\Python26;C:\Python26\Scripts
Run Code Online (Sandbox Code Playgroud)
当我在cmd.exe中键入此命令时:
easy_install cheetah
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
C:\Users\Richard>easy_install cheetah
'easy_install' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Richard>
Run Code Online (Sandbox Code Playgroud)
有帮助吗?在Windows XP中它工作.
我有一个简单的黑白唯一的GIF图像(400x400px让我们说).
我需要从该图像中获取所有像素,并查找它们是黑色还是白色.我需要创建一个字典,其中包含有关像素及其颜色的信息.
我对python很新,所以我有点挣扎.但到目前为止,这里是我的脚本:
#!/usr/bin/env python
import os
import Image
os.chdir("D:/python-projects")
aImage = Image.open("input.gif")
aPixelsBlackOrWhiteDictionary = {}
# now I need to fill the dictionary with values such as
# "X,Y": 0
# "X,Y": 1
# where X,Y are coordinates and 0/1 i the pixel color (b/w)
Run Code Online (Sandbox Code Playgroud)
基本上我希望最终字典是这样的:
"0,0" : 0 # pixel with X=0,Y=0 coordinates is black
"1,0" : 1 # pixel with X=1,Y=0 coordinates is White
Run Code Online (Sandbox Code Playgroud)
编辑:
当我尝试:
print aImage[0, 0]
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Traceback (most recent call last):
File "D:\python-projects\backprop.py", …Run Code Online (Sandbox Code Playgroud)