ruby-on-rails-3 – 样式占位符与best_in_place的值不同
发布时间:2020-12-17 04:24:17 所属栏目:百科 来源:网络整理
导读:我认为我遗漏了一些东西,因为似乎没有办法通过CSS来区分best_in_place值和占位符(data-nil =“输入你的号码”).我只想将占位符设置为与实际值不同,因此它看起来并不令人困惑. 我查看了事件,实际上可以在元素中添加一个类,但是当它们第一次显示在页面上时,没
我认为我遗漏了一些东西,因为似乎没有办法通过CSS来区分best_in_place值和占位符(data-nil =“输入你的号码”).我只想将占位符设置为与实际值不同,因此它看起来并不令人困惑.
我查看了事件,实际上可以在元素中添加一个类,但是当它们第一次显示在页面上时,没有可用于添加该类的事件.此时我会迭代每个$(‘best_in_place’)并将nil值与span中的html值进行比较,但是在我这样做之前,我只是想知道我是否错过了什么. 那么有没有办法区分已使用best_in_place设置的值? 如果代码让你理解得更好:这很有效,只需将类添加或删除到best_in_place,但只有在用户编辑字段时才设置,而不是在初始页面加载时设置. $('.best_in_place').bind('best_in_place:update',function(evt){ if($(this).data('nil') == $(this).html()){ $(this).removeClass('has_value'); }else{ $(this).addClass('has_value'); } }); 解决方法
谢谢你的代码.我解决了这个问题
在我的example.js.erb中 $('.top-column .best_in_place').each(function() { var element = $(this); if(element.data('nil') != element.text()) { updateBestInPlace($(this)); } }); 在example.js中 $(document).ready(function(){ $('.top-column .best_in_place').live("ajax:success",function(){ updateBestInPlace($(this)); }); }); function updateBestInPlace(element){ if(element.data('nil') == element.html() || element.html() == ""){ element.removeClass('has_value'); }else{ element.addClass('has_value'); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读