ruby-on-rails-3 – 样式占位符与best_in_place的值不同

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – 样式占位符与best_in_place的值不同前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我认为我遗漏了一些东西,因为似乎没有办法通过CSS来区分best_in_place值和占位符(data-nil =“输入你的号码”).我只想将占位符设置为与实际值不同,因此它看起来并不令人困惑.

我查看了事件,实际上可以在元素中添加一个类,但是当它们第一次显示页面上时,没有可用于添加该类的事件.此时我会迭代每个$(‘best_in_place’)并将nil值与span中的html值进行比较,但是在我这样做之前,我只是想知道我是否错过了什么.

那么有没有办法区分已使用best_in_place设置的值?

如果代码让你理解得更好:这很有效,只需将类添加删除到best_in_place,但只有在用户编辑字段时才设置,而不是在初始页面加载时设置.

  1. $('.best_in_place').bind('best_in_place:update',function(evt){
  2. if($(this).data('nil') == $(this).html()){
  3. $(this).removeClass('has_value');
  4. }else{
  5. $(this).addClass('has_value');
  6. }
  7. });
@H_301_10@

解决方法

谢谢你的代码.我解决了这个问题

在我的example.js.erb中

  1. $('.top-column .best_in_place').each(function() {
  2. var element = $(this);
  3.  
  4. if(element.data('nil') != element.text()) {
  5. updateBestInPlace($(this));
  6. }
  7. });

在example.js中

  1. $(document).ready(function(){
  2. $('.top-column .best_in_place').live("ajax:success",function(){
  3. updateBestInPlace($(this));
  4. });
  5. });
  6.  
  7. function updateBestInPlace(element){
  8. if(element.data('nil') == element.html() || element.html() == ""){
  9. element.removeClass('has_value');
  10. }else{
  11. element.addClass('has_value');
  12. }
  13. }
@H_301_10@ @H_301_10@

猜你在找的Ruby相关文章