jQuery UI - 调用突出显示/错误 [英] jQuery UI - calling Highlight/Error
问题描述
对不起,如果这太明显了,但我在任何地方找不到任何正确的答案...
I'm sorry if this is too obvious but I can't find any proper answer anywhere...
有任何方法放置突出显示/错误消息,如本页右下方的消息: http://jqueryui.com/themeroller/ 通过简单地调用jquery ui函数?
Is there any way to place an highlight/error message like the ones on the bottom right of this page: http://jqueryui.com/themeroller/ by simply calling a jquery ui function?
我检查了源代码,但似乎找不到答案...他们硬编码html?
I inspected the source code but can't seem to find the answer... Do they hardcode the html?
感谢
------------------------------ ----------- 解决方案 ------------------------------- --------
----------------------------------------- SOLUTION ---------------------------------------
jQuery:(创建一个新文件,其中包含以下代码:
jQuery: (create a new file whatever.js and place the following code there
$(document).ready(function(){
if($("div.error")[0]){
createError($("div.error"));
}
if($("div.notice")[0]){
createHighlight($("div.notice"));
}
});
//functions start
function createHighlight(obj){
obj.addClass('ui-state-highlight ui-corner-all');
obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
}
function createError(obj){
obj.addClass('ui-state-error ui-corner-all');
obj.html('<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right:.3em;"></span>'+obj.html()+'</p>');
}
HTML:
只需创建de divs即可邮件如:
HTML: Simply create de divs that you want to place the messages like:
<div class="error"><b>ERROR:</b> The message goes here</div>
或通知:
<div class="notice"><b>NOTICE:</b> The message goes here</div>
您可以使用css为类设置样式。
you can then style the classes using css.
希望这有助于任何人。
--------------------------- -------------- 解决方案 ---------------------------- -----------
----------------------------------------- SOLUTION ---------------------------------------
推荐答案
没有jQuery UI函数在页面上放置错误;但是你可以使用jQuery将错误类应用到这样的元素:
There is no jQuery UI function to place an error on the page; however you can apply the error class using jQuery to elements like this:
$('#el').addClass('ui-state-error ui-corner-all'); // Rounded corners
$('#el').addClass('ui-state-error'); // Squared Corners
我希望这会有帮助!
这篇关于jQuery UI - 调用突出显示/错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!