我在Rails中发了一条推文.我需要生成的URL看起来像这样:
http://twitter.com/share?url=http%3A%2F%2Fexample.com&text=Hello%20World
Run Code Online (Sandbox Code Playgroud)
但有点复杂.基本上是一个附加了GET参数加载的URL
使用Rails的助手之一来生成这个链接会很不错,例如:
url_for("http://twitter.com/share", :url => "http://example.com", :text => "Hello world")
Run Code Online (Sandbox Code Playgroud)
但我没有发现任何有效的东西.有人有主意吗?
美好的一天,
有没有一个正则表达式,我可以用来在任何低于10的数字前加0?
我不是在寻找日期解析库,三元或if/else解决方案.(希望)
var currentDate = new Date(),
stringDate = currentDate.getFullYear() + "-" + currentDate.getMonth() + "-" + currentDate.getDate() + " " + currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds();
alert( stringDate ); //2011-10-17 10:3:7
Run Code Online (Sandbox Code Playgroud)
我想要一个可以应用于stringDate的RegExp来获得2011-10-17 10:03:07
非常感谢你!
您好我正在尝试为我的表单动态生成一些输入,但它不会发布生成的新输入,到目前为止我一直在搜索,我唯一能找到的是使表单成为身体标签,以及在我的应用程序的设计中,这是不可能的,所以有人可能知道会发生什么以及如何解决它?不,它不起作用.live().
HTML
<form name="order" id="newOrder" action="../core/query.php" method="post">
<input type="text" value="Search" id="itemSearch" class="search"/>
<input type="hidden" id="itemAdd"/>
<button type="button" class="boton" id="additem">Add</button>
<br>
<div id="items"></div>
<br>
<button type="submit" class="boton" > Submit</button>
<button type="reset" class="boton" style="float:right;"> Cancel</button>
</div>
</form>
Javascript
$('#additem').click(function(){
if($('#itemAdd').val()){
var rawr = $('<div></div>')
.css('display','none')
.html( '<br><table><td>'
+currItem.label+'</td><td> Size '
+currItem.size+'</td><td class="right">$'+currItem.price
+'</td></table> <input type="hidden" name="contents[]" value="'
+currItem.value+'"/>');
var mhm = currItem.price;
rawr.appendTo('#items').toggle(500).click(function(){
$(this).toggle(500,function(){
$(this).remove();
});
$('#total').fadeOut("fast",function(){
total = (parseFloat($(this).text())-parseFloat(mhm)).toFixed(2);
$(this).text(total).fadeIn("fast");
});
});
$('#total').fadeOut("fast",function(){
total = (parseFloat($(this).text())+parseFloat(mhm)).toFixed(2);
$(this).text(total).fadeIn("fast");
currItem=null;
}); …Run Code Online (Sandbox Code Playgroud) 我已经阅读了关于事件处理的jQuery文档,但我仍然无法理解我应该做什么.
我有一个移动应用程序,其中内容加载了ajax,因此事件不能绑定到文档onLoad上的内容.
随着我的应用程序的增长,我现在开始担心错误的事件处理会给性能带来问题.
对on(),live()和delegate()之间的性能选择有何影响?
还有其他需要考虑的因素吗?
我在我的Rails 3应用程序中有一个表单,我想在方法上创建select一年的标签:grad_year.我有一切工作 - 和存储 - 正确使用date_select和添加:discard_month和:discard_day.但是,当我渲染时,@profile.grad_year我得到了月和日值.所以,我不知道如何来存储和渲染 仅在一年@profile.grad_year?
这是表格:
<%= f.date_select :grad_year, {:start_year => Time.now.year, :end_year => Time.now.year - 95, :discard_day => true, :discard_month => true}, :selected => @profile.grad_year %>
Run Code Online (Sandbox Code Playgroud)
在我的迁移中:
t.date :grad_year
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个使用Dropkick.js插件来设置选择框样式的项目.我们遇到的一个问题是,dropkick虽然看起来不错,但却不会反映选择框的方法,属性和事件.
我必须编写许多额外的代码来禁用/启用选择,获取和设置值以及许多其他东西,以使选择与网站的其余部分一起玩得很好并与其他表单元素交互.
所以我们切换到测试selectBox.Fantasic插件有一个例外:如果您通过ajax和jQuery删除/添加选择页面,它会破坏页面中每个选择的设置.这会导致整个地方出现无法使用的选择和JS错误.由于我们正在做很多动态内容,所以这也行不通.
是否有一个GOOD选择插件,它公开了选择框的所有方法和属性,可以很好地设计样式,并与动态内容一起使用?
谢谢你的建议!
我正在尝试生成一个快速注册表单,以便在我的应用程序上使用 Facebook、Twitter 和链接登录。但我确实有用户模型来验证之前注册过程中的某些字段。
我正在尝试扩展基于 Devise 的注册控制器,以便使用相同的数据库从外部登录快速注册。这个问题的制定是因为我正在运行试用,然后我有一个注册表单要求信用卡。
我有这个控制器:
class Users::QuickRegistrationController < Users::RegistrationsController
self.model_class = Users::RegistrationsController
end
Run Code Online (Sandbox Code Playgroud)
然后我有这个用户模型:
class User < ActiveRecord::Base
validates :name, :presence => true
validates :first_surname, :presence => true
validates :prefered_language, :presence => true
validates :dni, :presence => true, :uniqueness => true #, :format => {:with => /(^\d{7,8}[a-zA-Z]$)|(^[a-zA-Z]\d{7}[a-zA-Z]$)/, :unless => "dni.blank?"}
validates :phone_number, :presence => true, :format => { :with => /^((\d{9})|([+]\d{11}))$/, :unless => "phone_number.blank?"}, :uniqueness => true
validates :birthdate, :presence => true, :age => {:adult => :over}
validates …Run Code Online (Sandbox Code Playgroud) 我在jQuery中遇到了一个好奇心:如果我调用.click()一个链接,就会调用click事件处理程序,但实际上没有跟踪链接(好像它是在浏览器中单击的那样):
<a id="link" href="http://www.google.com>Link</a>
$("#link").click() // won't take me to Google
Run Code Online (Sandbox Code Playgroud)
但是在普通的Javascript中,一切都按预期运行:
document.getElementById("link").click() // *will* take me to Google
Run Code Online (Sandbox Code Playgroud)
这显然是故意的行为 - 但我正在努力解决为什么这样click实施 - 链接的特殊例外?
在这里小提琴:http://jsfiddle.net/9a6sp/
澄清:我不是问如何点击JS中的链接,而是为什么jQuery中的默认行为实际上是在调用时没有点击链接.click()