Referring to this example:

http://vallandingham.me/stepper_steps.html

it seems that the D3 and jQuery libraries are very similar in the sense that they both do DOM manipulation in an object-chaining way.

I'm curious as to know what functions D3 makes easier than jQuery and vice versa. There are plenty of graphing and visualization libraries that use jQuery as a basis (e.g., , , ).

请给出具体的例子,说明它们的不同之处.

推荐答案

  • D3是data-driven,但jQuery不是:使用jQuery you directly manipulate个元素,但使用D3 you provide data and callbacks到D3独特的data()enter()exit()方法,D3操作元素.

  • D3通常用于数据可视化,但jQuery用于创建webapply.D3有很多数据可视化扩展,jQuery有很多Web应用插件.

  • 两者都是JavaScript DOM操作库,都有CSS Select 器和Fluent API,并且都基于使它们看起来相似的Web标准.

下面的代码是一个D3用法的示例,这在jQuery中是不可能的(请在jsfiddle中try ):

  // create selection
  var selection = d3.select('body').selectAll('div');

  // create binding between selection and data
  var binding = selection.data([50, 100, 150]);

  // update existing nodes
  binding
    .style('width', function(d) { return d + 'px'; });

  // create nodes for new data
  binding.enter()
    .append('div')
    .style('width', function(d) { return d + 'px'; });

  // remove nodes for discarded data
  binding.exit()
    .remove();

Jquery相关问答推荐

如何在Jquery和Laravel中使用请求传递两个参数给Datatable

formData.append 来自不同输入文件的两个文件

如何在外部JS文件中使用带有参数的laravel路由

如何使用 jquery 获取屏幕的高度

提醒未保存的表单更改

JavaScript 或 jQuery 字符串以实用函数结尾

TypeScript 中是否有this的别名?

如何在 jQuery 中修改序列化的表单数据?

使用 时如何从 select2 中获取选定文本

如何使用 requirejs 使 jQuery 插件可加载

Javascript 使用哈希值重新加载页面

所有但不是jQuery Select 器

jQuery ajax 成功回调函数定义

Backbone.js - 事件,知道点击了什么

如何通过jQuery函数仅获取直接子元素

jQuery或javascript查找页面的内存使用情况

Uncaught TypeError: undefined is not a function on loading jquery-min.js

使用 jquery 禁用文本框?

jQuery,简单的轮询示例

jQuery append() 与 appendChild()