- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用 select2 作为我选择的网站 UI。但是,我注意到有一个用于 select2 的特性,我觉得应该用于我的文本框;清除所有功能。
http://ivaynberg.github.io/select2/
我在网络上看到了很多关于如何将清除按钮添加到文本框元素的帖子,但似乎没有一个符合我的兴趣。因为我正在使用 select2,所以我希望我的输入框具有与我的 select2 相同的外观和感觉,包括“清除按钮”。
我能找到的最接近的功能控件位于此处:Clearing Search terms from input field. ,他给出了 demo found here.
这样做有两个缺点:
如果有人知道任何解决方案,那将是一个很好的帮助
最佳答案
这是我想出的解决方案:
请检查代码,看看是否可以进行任何调整。我使用的是 jquery,但决定将其作为 angular js 指令,因为它完全是 UI,与数据本身无关。
我从 html 开始:
<div clear-text>
<input ng-model="CustomerName" type="text" name="" value="" placeholder="Name" />
</div>
请注意,我的输入框周围必须有一个 div。为了让我的 X 出现,你需要有一个包装器。你会看到当我包含我的 css 时会发生什么:
.clearable{
display: inline-block;
*display: inline;
zoom: 1;
height:30px;
}
.clearable input
{
float: left;
background: transparent;
cursor:pointer;
}
.clearable.x{
background: transparent url(../themes/base/images/clearText-dark.png) no-repeat 95% center;
}
.clearable.onX{
background: transparent url(../themes/base/images/clearText-light.png) no-repeat 95% center;
}
要点是获得一个输入框,使面部皮肤透明,并让 div 处理图像的显示方式。棘手的部分是实际功能。
这是我的 Angular Directive(指令):
app.directive('clearText', function () {
var directiveDefinitionObject = {
link: function link(scope, element, attrs) {
element.addClass("clearable");
function tog(v) { return v ? 'addClass' : 'removeClass'; }
element.keyup(function () {
element[tog(element.children('input[type=text]:only-child').val())]('x');
}).mousemove(function (e) {
e.preventDefault();
if (element.hasClass('x')) {
element[tog(((this.offsetWidth - 30) < (e.clientX - this.getBoundingClientRect().left)) &&
((this.offsetWidth - 5) > (e.clientX - this.getBoundingClientRect().left)) &&
((this.offsetHeight - 30) < (e.clientY - this.getBoundingClientRect().top)) &&
((this.offsetHeight - 5) > (e.clientY - this.getBoundingClientRect().top)))]('onX');
}
}).click( function (e) {
e.preventDefault();
if (element.hasClass('onX')) {
element.removeClass('x onX');
element.children('input[type=text]:only-child').val('');
}
});
}
};
return (directiveDefinitionObject);
}]);
我想指出几件事。我拒绝在 $document 上做,因为我希望每个元素都相互隔离。所以如果你制作多个文本框,这不会影响另一个。其次,mousemove 用于创建一个小“窗口”,允许 X 的颜色在鼠标悬停在其上时发生变化。
这是 jsfiddle:http://jsfiddle.net/8T27H/2/
在ie7、ie8、ie9、chrome、操作、firefox上测试
关于jquery - 输入文本框 : mimic "clear text" X button just like select2 dropdown component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21468669/
谁能告诉我为什么 的技术原因在 app.config 与 中无效 通常这样使用: 问题是我正在使用安装程序产品 (InstallShield) 将 xml 转换为 app.config
在Linux上,使用崇高的文本。Os.system(‘Clear’)应该只清除控制台窗口。用于Windows的os.system(‘cls’)。但它回来的时候和我不一样。。代码:。退货:。为什么在Cl
这个问题在这里已经有了答案: How can I force the STL memory cache to clear? (2 个答案) 关闭 6 年前。 我在 Solaris 10 上使用 g+
official docs关于 .clear() 我不是很清楚。他们说: Erases all AsyncStorage for all clients, libraries, etc. You pr
我有这段代码可以清除 C# WebBrowser 控件中的缓存。它的问题是它还会清除 cookie。在整个互联网上,我似乎是唯一一个不想这样的人。 我需要维护 cookie,但要丢弃缓存。 特别感兴趣
我记得直接在 DataTable 上调用的一些方法/属性之间存在差异。类,以及 DataTable.Rows 上同名的方法/属性属性(property)。 (可能是我读到这篇文章的 RowCount/
在 Unity 的 Camera组件中有一个属性清除标志,它允许从四个选项中进行选择:天空盒、纯色、仅深度和不清除。 正如文档所说: Don’t clear This mode does not cl
我无法找出为什么我的函数没有被调用。我将 alert("test") 放在那里只是为了测试函数是否被调用,而事实并非如此。 HTML: JS: function clear(price,quanti
我有 2 个数组列表: ArrayList> res= new ArrayList(); ArrayList data= new ArrayList(); 在我将结果集添加到子项并将子项附加到父项后,
正如主题所述..哪个版本更有效,为什么? std::vector a; .. a.clear(); 或 std::vector a; .. if(!a.empty()) a.clear(); 最佳
我包含了定义函数“clear()”的“PDCurses/curses.h”,然后当我使用“std::wstring::clear()”时,msvc-10.0 编译器报告错误。当我在包含后使用“#und
Session.Clear() 与 Session.Contents.Clear() 有什么区别? 我想清除所有 session 变量。 谢谢。 最佳答案 根据反射器,没有差异。 Session.Co
QPointer有一个方法, clear() . Clears this QPointer object. 我不确定“清晰”的确切含义。在我看来,这可能意味着 它会删除您引用的指针。 或 它取消附加您
在 string::clear 函数的描述中,它说: clear: Erases the contents of the string, which becomes an empty string (
我有两个不同的 Mathematica 笔记本,它们具有相似但功能不同的功能。当它们是唯一打开的笔记本时,两者都可以正常工作。尽管我(自由地)使用 Clear[] 来清除相关变量,但其中一个在另一个笔
有没有办法扩展 Symfony 2 cache:clear命令来清除 APC 还是执行一些其他逻辑? 最佳答案 您可以使用 ApcBundle去做这个。 关于php - 扩展 Symfony 2 缓存
我正在尝试使用 html 和 css 制作一个简单的信息网站,并使用 960 网格,因为该网站将具有分栏结构。 当我将标题 h1 float 到左侧(它有 Logo 图像,我正在使用 css 添加图像
我刚刚意识到: 在一系列 float div 导致布局破坏之后,同时 工作正常。 谁能解释一下? 这是 CSS: div.clear { clear:both; } 最佳答案 如果您将
这两个命令等效吗?如果不是,有什么区别? 最佳答案 rake 任务仅清除存储在文件系统 "#{Rails.root}/tmp/cache" 中的文件。这是该任务的代码。 namespace :cach
在STM32F407上初始化USART1时,我在启用TC中断时遇到了问题。一旦 USART RCC 启用,SR 中的 Tcflags就会被设置(“1”),而在启用 TC 中断之前清除该标志对我来说已经
我是一名优秀的程序员,十分优秀!