jQuery检测类分配的变化 [英] jquery detect change in class assignment
本文介绍了jQuery检测类分配的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道使用JQuery检测给定元素的类何时已更改的方法吗?
Does anyone know a way to detect when a given element's class has changed using JQuery?
我正在使用简单计数" JQuery插件来通知用户输入文本区域的字符数.当用户超过允许的字符数时,我想禁用发布"按钮.
I'm using the "simply countable" JQuery plug-in to notify the user of the number of characters entered into a text area. When the user exceeds the allowed number of characters, I would like to disable the "post" button.
由于达到限制时,简单的可计数更改分配的CSS类,我的想法是捕获该事件,以便可以禁用发布按钮,但是也许有更好的方法吗?
Since simply countable changes the assigned CSS class when the limit is reached, my idea was to capture that event so that I could disable the post button, but perhaps there is a better way?
欢迎提出任何建议.
谢谢.
推荐答案
您的意思是这样的吗?
<script>
$("#myTextArea").change(function(){
var contentLength = $(this).val().length;
var charLimit = 500;
if(contentLength > charLimit){
$("#saveButton").attr("disabled","disabled");
}
});
</script>
<textarea id="myTextArea"></textArea>
<input type="submit" id="saveButton">
这篇关于jQuery检测类分配的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文