jQuery UI + Rails
jQuery UI + Rails
我有以下代码在我的网站上的haml文件:
= stylesheet_link_tag "web-app-theme/base2", "web-app-theme/themes/activo/style", "web-app-theme/override", 'web-app-theme/tabs'
= javascript_include_tag 'tabber.js', 'jquery-1.3.2.min.js', 'jquery-ui-1.7.custom.min.js'
:javascript
$(function() {
var $tabs = $('#tabs').tabs();
$(".ui-tabs-panel").each(function(i){
var totalSize = $(".ui-tabs-panel").size() - 1;
if (i != totalSize) {
next = i + 2;
$(this).append("Next Page »");
}
if (i != 0) {
prev = i;
$(this).append("« Prev Page");
}
});
$('.next-tab, .prev-tab').click(function() {
$tabs.tabs('select', $(this).attr("rel"));
return false;
});
});
#page-wrap
#tabs
%ul
%li
%a{:href => "#fragment-1"} 1
%li
%a{:href => "#fragment-2"} 2
%li
%a{:href => "#fragment-3"} 3
%li
%a{:href => "#fragment-4"} 4
%li
%a{:href => "#fragment-5"} 5
%li
%a{:href => "#fragment-6"} 6
%li
%a{:href => "#fragment-7"} 7
%li
%a{:href => "#fragment-8"} 8
%li
%a{:href => "#fragment-9"} 9
%li
%a{:href => "#fragment-10"} 10
%li
%a{:href => "#fragment-11"} 11
%li
%a{:href => "#fragment-12"} 12
%li
%a{:href => "#fragment-13"} 13
%li
%a{:href => "#fragment-14"} 14
%li
%a{:href => "#fragment-15"} 15
#fragment-1.ui-tabs-panel
%p Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.
#fragment-2.ui-tabs-panel.ui-tabs-hide
%p Donec ultricies senectus tristique egestas vitae, et ac morbi habitant quam sit mi quam, malesuada leo. Vestibulum tempor Mauris tortor libero eget, egestas. eu vitae feugiat netus amet Pellentesque ante. amet, ultricies eleifend turpis sit placerat et semper. Aenean est. fames
#fragment-3.ui-tabs-panel.ui-tabs-hide
%p ante. Mauris Vestibulum est. fames egestas quam, leo. amet tristique sit libero egestas. ultricies mi turpis senectus Pellentesque habitant eu ac morbi netus eget, Aenean malesuada vitae, semper. eleifend et feugiat vitae amet, placerat Donec et tortor ultricies tempor quam sit
#fragment-4.ui-tabs-panel.ui-tabs-hide
#fragment-5.ui-tabs-panel.ui-tabs-hide
#fragment-6.ui-tabs-panel.ui-tabs-hide
#fragment-7.ui-tabs-panel.ui-tabs-hide
#fragment-8.ui-tabs-panel.ui-tabs-hide
#fragment-9.ui-tabs-panel.ui-tabs-hide
#fragment-10.ui-tabs-panel.ui-tabs-hide
#fragment-11.ui-tabs-panel.ui-tabs-hide
#fragment-12.ui-tabs-panel.ui-tabs-hide
#fragment-13.ui-tabs-panel.ui-tabs-hide
#fragment-14.ui-tabs-panel.ui-tabs-hide
#fragment-15.ui-tabs-panel.ui-tabs-hide
%p The end.
代码很好,因为它创建了正确的选项卡界面,但是按钮不工作,它们只是显示为文本,所以我想知道是否有我应该做的事情,使javascript正常工作?我试着在haml文件中删除javascript代码,并把它放在application.js:
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
$(function() {
var $tabs = $('#tabs').tabs();
$ (".ui-tabs-panel").each(function(i){
var totalSize = $(".ui-tabs-panel").size() - 1;
if (i != totalSize) {
next = i + 2;
$(this).append("Next Page »");
}
if (i != 0) {
prev = i;
$(this).append("« Prev Page");
}
});
$('.next-tab, .prev-tab').click(function() {
$tabs.tabs('select', $(this).attr("rel"));
return false;
});
});
这只会导致标签布局中断,不再正常工作。
所以问题是来自jquery站点的原始代码都是html格式的-当它转换为haml时,它也从javascript部分删除了html。这会使javascript链接无法正常工作。经验教训:不要通过haml2html运行javascript。
相关文章:
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- jQuery UI自动完成突然停止工作
- 如何使用skip参数使用angular ui引导进行服务器端分页
- AngularJS UI路由器不能像ng路由器那样工作
- Rails/JSON:如何将JSON用于jquery UI自动完成表单
- Angularjs UI视图和Rails服务器端模板路由
- jquery-ui-rails的draggable和dropable函数不起作用
- Ruby on Rails:“找不到文件'jquery.ui.datepicker'”
- jquery UI Datepicker 在我的 Rails 应用程序中不起作用
- jQuery UI + Rails
- 我的jquery-ui-rails的咖啡脚本不工作
- Rails REST API权限(CanCan)与Angular JS客户端.如何基于权限呈现UI
- jQuery UI自动完成在rails应用程序中不起作用
- jQuery UI Datepicker和Rails不兼容
- Jquery UI不能与rails 4一起工作
- Rails 4-区别//=需要jquery.ui.all或使用CDN
- 在Rails应用中使用jQuery UI自动完成插件
- JQuery UI自动完成在Rails应用程序几乎工作,但我不能导航或点击菜单
- Rails 4 and jQuery UI
- 在rails应用程序中对Javascript繁重的UI进行集成测试的最佳方法是什么?