WordPress解决方案在jquery 1.11.0中不工作
Word Counter plugin in textarea WordPress solution not working in jquery 1.11.0
我已经用这个线程的代码设置了我的表单:计数和限制文本区域中的单词
然而,小提琴代码是用jQuery 1.8.3编写的,它工作得很好,然而,我的wordpress网站使用jQuery 1.11.0 -我需要对代码做什么样的修改才能使用这个版本的jQuery ?下面的代码…
谢谢你的帮助。
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'>//<![CDATA[
$(function(){
$(document).ready(function() {
$("#word_count").on('keydown', function(e) {
var words = $.trim(this.value).length ? this.value.match(/'S+/g).length : 0;
if (words <= 200) {
$('#display_count').text(words);
$('#word_left').text(200-words)
}else{
if (e.which !== 8) e.preventDefault();
}
});
});
});//]]>
</script>
<textarea name="txtScript" id="word_count" cols="30" rows="10"></textarea>
Total word Count : <span id="display_count">0</span> words. Words left : <span id="word_left">200</span>
好吧,这不是jQuery版本有影响,如果我改变你在这引用的fiddle计数和限制单词在文本区域的答案在这里找到http://jsfiddle.net/7DT5z/9/使用jQuery 1.11.0,如这里所见http://jsfiddle.net/robschmuecker/7DT5z/21/它仍然工作。
我相信这是jQuery默认包含在wordpress中的方式,你在正常模式下引用jQuery,但它默认包含在wordpress的noConflict
模式中,这意味着$
(别名如果jQuery
)不可用,你需要使用jQuery
。
所以你的代码需要读:
jQuery(function(){
jQuery(document).ready(function() {
jQuery("#word_count").on('keydown', function(e) {
var words = jQuery.trim(this.value).length ? this.value.match(/'S+/g).length : 0;
if (words <= 200) {
jQuery('#display_count').text(words);
jQuery('#word_left').text(200-words)
}else{
if (e.which !== 8) e.preventDefault();
}
});
});
});
另一种更简单的修改引用缩写别名$
的代码的方法是这样的。-正如这里漂亮的解释和演示http://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/
jQuery(document).ready(function( $ ) {
$("#word_count").on('keydown', function(e) {
var words = $.trim(this.value).length ? this.value.match(/'S+/g).length : 0;
if (words <= 200) {
$('#display_count').text(words);
$('#word_left').text(200-words)
}else{
if (e.which !== 8) e.preventDefault();
}
});
});
相关文章:
- 可以转换显示属性吗?如果没有,什么'这是最好的解决方案
- iPad虚拟键盘-哪一个-javasctript解决方案
- AJAX HTTP基本身份验证解决方案
- 在chrome web商店中打开时,是否有允许执行内容/后台脚本的解决方案
- Chart.js-添加渐变而不是纯色-实现解决方案
- learnyounode杂耍异步解决方案不工作
- 了解因子分解解决方案
- 我根据解决方案按类对
- 元素进行分组,但需要帮助了解它的工作原理
- JavaScript没有'JSP页面重定向后无法工作..任何解决方案
- 数据切换和onclick不能一起工作,我太新了,无法应用@epascarello的解决方案
- Javascript在页面刷新后工作,不知道解决方案
- 如何修改给定的代码打开两个链接在一次点击(没有解决方案为我工作)
- WordPress解决方案在jquery 1.11.0中不工作
- 你如何得到解决方案的屏幕宽度和高度工作
- 为什么这个setTimeout解决方案不能在javascript中工作
- Javascript拖放:ondragleave工作解决方案
- AngularJs:返回已经找到的嵌套$http解决方案的承诺,但为什么它能工作
- 寻找一个解决方案,作为radiobutton.click()挂Safari,但在Chrome中工作
- 文档.execCommand复制命令不工作或其他解决方案
- jquery是(“;: focus")在safari中不工作.如果任何解决方案($ ().parents(&