[英]Is Using Javascript inside a jQuery function is a bad practice?
I know basics of both jQuery and JavaScript.I would like to follow a good coding practice. 我了解jQuery和JavaScript的基础知识。我想遵循良好的编码习惯。 Is using JavaScript inside a jQuery function is a bad practice?
在jQuery函数中使用JavaScript是一种不好的做法吗?
For exapmle: 例如:
$(document).ready( function() {
$('#dqualification').change(function() {
document.getElementById("demo").innerHTML = "Resolve following errors";
});
});
Nope, its fine, and it's done all the time. 不,很好,而且一直都在做。
Consider: 考虑:
$("#myDiv").on("click", function(){
var a = this;
});
The line var a = this;
这行
var a = this;
is pure JavaScript. 是纯JavaScript。 There is no "jQuery Version" of
var a = this;
没有
var a = this;
“ jQuery版本” var a = this;
. 。
jQuery provides convenient ways of doing things in JavaScript that might be difficult to write and code yourself in pure JavaScript. jQuery提供了使用JavaScript进行操作的便捷方法,这些方法可能很难用纯JavaScript编写和编写。 It doesn't replace JavaScript, it just 'adds to it'.
它不会替代JavaScript,而只是“添加”。
Remember, jQuery is just a JavaScript library. 记住,jQuery只是一个JavaScript库。 So everything ends up as JavaScript at the end of the day.
因此,一切最终都将以JavaScript结束。
It is not directly bad practice , it is more a bit inconsistend. 这不是直接的坏习惯 ,更多的是前后矛盾。 Both is
javascript
. 两者都是
javascript
。 But why would you do things like in your example? 但是,为什么要像您的示例那样做呢? If you have jQuery available, you could use it!
如果您有可用的jQuery,则可以使用它!
$(function() {
$('#dqualification').change(function() {
$("#demo").html("Resolve following errors");
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.