我已经尝试过但没有找到...我怎样才能改变我用on()方法编写的以下方法?
//Get old posts when scrolling down
$(window).scroll(function(){
if($(window).scrollTop()==($(document).height()-$(window).height())){
//Get older posts
$.ajax({
type: 'POST',
url: 'action/getoldposts.php',
success: function(oldposts){
//Append #postsDiv
$('#postsDiv').append(oldposts);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
提前致谢!
丹尼斯
更新1
我将代码更改为以下内容,但是随后创建的内容没有功能 - 我是否缺少一些静态引用?
$(window).on('scroll',function(){
if($(window).scrollTop()==($(document).height()-$(window).height())){
//Get older posts
$.ajax({
type: 'POST',
url: 'action/getoldposts.php',
success: function(oldposts){
//Append #postsDiv
$('#postsDiv').append(oldposts);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
更新2
动态创建的元素错过了以下功能:
$('#postsDiv').on('keydown', '.commenttext', function(e) {
if ((e.which == 13) && !e.shiftKey) {
comment($(this));
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
方法comment()如下所示:
//Function to comment on a post
function comment(commenttext)
{
//Get …Run Code Online (Sandbox Code Playgroud) 我有一个用户和一个文档模型;一个用户有很多文档,一个文档属于一个用户。您可以将其概括为只有一个父模型和一个子模型。
现在我正在为子模型编写单元测试,我想知道我是否也必须验证 parent_id 字段(例如 only_integer,大于零,id 存在于父表中等) - 还是 Rails 自动执行因为这些是固有的外键属性,所以对我这样做吗?
我克隆了一个现有的存储库,现在正在运行bundle install- 由于某种原因,它在ruby-audio gem失败了.
Installing ruby-audio (1.6.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/thisuser/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for sndfile.h in /opt/local/include,/usr/local/include,C:/Program Files (x86)/Mega-Nerd/libsndfile/include,C:/Program Files/Mega-Nerd/libsndfile/include... no
checking for sf_open() in -lsndfile-1... no
checking for sf_open() in -lsndfile... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include …Run Code Online (Sandbox Code Playgroud) %tbody
- @accounts.each do |account|
%tr
%td= link_to account['id'],show_path,{:id => account['id']}
%td= account['name']
%td= account['description']
%td= account['created']
Run Code Online (Sandbox Code Playgroud)
以上只是haml文件的一个片段,在我的控制器中我有以下内容:
def show
# If a system account already exists in session, it was found from a search with the account id
# Otherwise, this is a new search for a system account by the given id
@account = session[:account]
if @account.nil?
Rails.logger.debug { "Querying for the account with id: #{params[:id]}" }
response = query_account(CGI.escape(params[:id]))
@account = JSON.parse(response.body)
end
end
Run Code Online (Sandbox Code Playgroud)
路径(show_path)是/ system_accounts /:id …
我有一个名为参与者的表,其中包含以下字段:
背景是与至少两个或更多参与者进行对话.我想找到一个仅由两个指定用户持有的对话,而对话中没有其他用户.
我想出了以下内容:
SELECT *
FROM participants
WHERE user_id = 1 OR user_id = 2
GROUP BY conversation_id
HAVING COUNT(*) = 1
Run Code Online (Sandbox Code Playgroud)
鉴于此内容
参与者表格图像http://s12.postimage.org/af4xrfoax/table.png
您可以看到用户1和2与用户3(对话1)共享对话,但也只有一个对话(对话2).
上面的查询实际上返回了正确的conversation_id(即2) - 但我不确定查询是否正确.当我说它HAVING COUNT(*) = 2返回对话1时,我不知道为什么.直觉上我使用了计数 - 如果设置为1似乎也可以工作 - 但我不确定它在这种情况下是做什么的.
查询是否正确?如果是这样,为什么?如果没有,我需要更改什么才能使其正常工作?
深入研究文档和api,我似乎错过了如何一次更新多行中的一个字段.
就像是
Table.select(:field).update("update to this").where(id: 4,5,6)
Run Code Online (Sandbox Code Playgroud)
会好的.
这样的事情存在吗?这比将所有内容存储在数组中,将其设置为值以及save每次调用要好得多.
我试图像这样捕获一个arity异常:
(try
(inc)
(catch clojure.lang.ArityException e
(str "caught exception: " (.getMessage e))))))
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我调用时inc没有传递数字,它正确地引发异常.但是,当我运行它时,该异常不会被捕获:
(try
(inc)
(catch clojure.lang.ArityException e
(str "caught exception: " (.getMessage e))))))
; => CompilerException clojure.lang.ArityException: Wrong number of args (0) passed to: core/inc--inliner--4489
Run Code Online (Sandbox Code Playgroud)
试图抓住任何Exception一般而不是clojure.lang.ArityException仍然抛出它.
我相信任何在Clojure开发中经验丰富的人都会立即抓住我的错误.
我总是在浏览器Safari的源代码中看到这一点,虽然它不是页面源代码的一部分 - 它就像Safari总是把它放在其余的前面.
<script type="text/javascript">window["_gaUserPrefs"] = { ioo : function() { return true; } }</script>
Run Code Online (Sandbox Code Playgroud)
我在某处读到它用于向Google发送浏览行为的偏好,但我不知道是否有任何这种情况.
在任何情况下:我怎么能摆脱它?
谢谢!
丹尼斯
我有用户输入并使用htmlentities()来转换所有实体.但是,似乎有一些错误.当我输入
ääää öööö üüüü ääää
Run Code Online (Sandbox Code Playgroud)
我明白了
ääää öööö üüüü ääää
Run Code Online (Sandbox Code Playgroud)
看起来像这样
ääääÃÃÃÃÃüüüüüüüääää
我究竟做错了什么?代码实际上只是这样:
$post=htmlentities($post);
Run Code Online (Sandbox Code Playgroud)
编辑1
这里有一些我用于格式化的代码(它们有一些有用的功能):
//Secure with htmlentities (mysql_real_escape_string() comes later)
$post=htmlentities($post);
//Strip obsolete white spaces
$post = preg_replace("/ +/", " ", $post);
//Detect links
$pattern_url='~(?>[a-z+]{2,}://|www\.)(?:[a-z0-9]+(?:\.[a-z0-9]+)?@)?(?:(?:[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])(?:\.[a-z](?:[a-z0-9]|(?<!-)-)*[a-z0-9])+|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:/[^\\/:?*"<>|\n]*[a-z0-9])*/?(?:\?[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?(?:&[a-z0-9_.%]+(?:=[a-z0-9_.%:/+-]*)?)*)?(?:#[a-z0-9_%.]+)?~i';
preg_match_all($pattern_url, $post, $matches);
for ($i=0; $i < count($matches[0]); $i++)
{
if(substr($matches[0][$i],0,4)=='www.')
$post = str_replace($matches[0][$i],'http://'.$matches[0][$i],$post);
}
$post = preg_replace($pattern_url,'<a target="_blank" href="\\0">\\0</a>',$post);
//Keep line breaks (more than one will be stripped above)
$post=nl2br($post);
//Remove more than one linebreak
$post=preg_replace("/(<br\s*\/?>\s*)+/", "<br/>", $post);
//Secure with mysql_real_escape_string()
$post=mysql_real_escape_string($post);
Run Code Online (Sandbox Code Playgroud) 我有一个位于页面顶部的div,位于标题栏的正下方.当用户向下滚动并且栏向上移动时,我希望它只上升到浏览器窗口的边缘然后保持在那里,就像固定一样.
怎么可能?仅使用CSS是可行的还是我需要jQuery?我更喜欢jQuery用于跨浏览器兼容性.
这是我目前使用的简单和简单的CSS代码:
#fbLikeDiv
{
position: fixed;
top: 95px;
left: 10px;
}
Run Code Online (Sandbox Code Playgroud)
您还可以查看该网站:www.myskoob.com/postish/ - 它是关于左侧Facebook的框,我想在用户向下滚动时保持在浏览器窗口的顶部边缘,但首先去直到那里.
我在jQuery中有一个包含19个字段的数组,并且想要随机提醒一个.我在考虑一些Math.rand()?
谢谢!
丹尼斯