我正在将链接转换为复选框。
我想要这个
<%= link_to (image_tag "table.png", :alt => "Show Area(s) Table", :style => "padding-left:15px;", :id => "updateAreaTableIconId"), refresh_area_table_path({:field_id => "#{@field.id}"}), :remote => true %> 然后创造出像这样的东西
<input type='checkbox' id='showAreaBox' onclick='showArea(); <%= redirect_to refresh_area_table_path({:field_id => "#{@field.id}"}), :remote => true %>;'></input> 换句话说,我想摆脱链接,并将重定向添加到复选框的onclick
如果有办法在jquery中触发远程重定向,我也可以将其添加到showArea();方法中。
谢谢!
发布于 2013-07-16 21:09:15
我是web开发的新手,现在我意识到我问的问题不对。
我最终使用了这个
$.post('myLink')这做了什么:远程=>真的在link_to上做了什么。我在这篇文章的2. http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/上找到了答案
发布于 2013-07-15 23:13:07
听起来您想在选中复选框时以编程方式单击锚点?
这里有一种方法:
var myLink = $('#myLinkId'); // assumes you have a reference to your <a/> element
$('#showAreaBox').change(function() {
// if the checkbox is checked, invoke the link
if( this.checked ) {
myLink.trigger('click');
}
// checkbox is unchecked
// else {}
});发布于 2013-07-15 23:26:18
试试这个:
JS
$('#showAreaBox').change(function() {
var el = $(this);
if (el.prop('checked')) {
if (el.data('target') == '_blank') {
window.open(el.data('link'));
}
else {
location = el.data('link');
}
}
});用于在同一窗口中打开的HTML
<input type="checkbox" id="showAreaBox" data-link="http://www.example.com">用于在新窗口中打开的HTML
<input type="checkbox" id="showAreaBox" data-target="_blank" data-link="http://www.example.com">https://stackoverflow.com/questions/17657521
复制相似问题