How to addClass('ui-state-error') to a <select> styled with selectmenu, dropkick and/or chosen plugin?

老子叫甜甜 提交于 2020-01-30 10:58:25

问题


There are a few plugins ( selectmenu, dropkick, chosen, and probably many more ) that turn tag combo-box into a prettier, styled, more functional version.

I'd like to style the extended tag with ui-state-error style. This sporadically works sometimes, but most of the time it doesn't:

$('select').selectmenu().addClass('ui-state-error');

And even when it works, removeClass('ui-state-error') doesn't work.

So, what is the correct way to addClass('ui-state-error') to one of these extended combo-boxes?


回答1:


See my JSFiddle here.

From what I can see, you should use the following:

 $('select').selectmenu();
 $('.ui-selectmenu').addClass('ui-state-error');

This will achieve the effect you desire, but it's going to cause an issue when you have multiple selects on the page. This is where you get into the specific of each implementation. As for selectmenu, it seems you should be able to do the following:

 id = $('select')[0].id;
 $('#' + id + '-button').addClass('ui-state-error');

But, that's very specific on a plugin with very little documentation. Feel free to use this as a jumping off point. Enjoy!



来源:https://stackoverflow.com/questions/7055626/how-to-addclassui-state-error-to-a-select-styled-with-selectmenu-dropkick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!