Javascript 如何在jQuery函数中使用options var?
我得到了一个脚本,名为,我想使用它。它允许我通过插入变量在div之间画一条线。作者告诉我要像这样使用它:Javascript 如何在jQuery函数中使用options var?,javascript,jquery,html,Javascript,Jquery,Html,我得到了一个脚本,名为,我想使用它。它允许我通过插入变量在div之间画一条线。作者告诉我要像这样使用它: $.line(fromPoint, toPoint[, options]); 其中一个选项名为className,我想用它向.jquery行添加一个额外的.blue类,因此所有创建的div看起来都像 默认选项如下所示: $.line.defaults = { className: 'jquery-line', lineWidth: 1, lineColor: '#0
$.line(fromPoint, toPoint[, options]);
其中一个选项名为className
,我想用它向.jquery行
添加一个额外的.blue
类,因此所有创建的div看起来都像
默认选项如下所示:
$.line.defaults = {
className: 'jquery-line',
lineWidth: 1,
lineColor: '#000',
returnValues: false
};
var firstDot = $(this);
var secondDot = dots.eq( currentIndex + 1 + offset);
firstDot.y = firstDot.offset().top;
firstDot.x = firstDot.offset().left;
secondDot.y = secondDot.offset().top;
secondDot.x = secondDot.offset().left;
$.line(firstDot, secondDot);
$.line(firstDot, secondDot, {className: "blue"});
$.line(firstDot, secondDot, {className: 'jquery-line blue'})
我的底线是这样的:
$.line.defaults = {
className: 'jquery-line',
lineWidth: 1,
lineColor: '#000',
returnValues: false
};
var firstDot = $(this);
var secondDot = dots.eq( currentIndex + 1 + offset);
firstDot.y = firstDot.offset().top;
firstDot.x = firstDot.offset().left;
secondDot.y = secondDot.offset().top;
secondDot.x = secondDot.offset().left;
$.line(firstDot, secondDot);
$.line(firstDot, secondDot, {className: "blue"});
$.line(firstDot, secondDot, {className: 'jquery-line blue'})
如何添加额外的类名?我尝试了以下方法:
$.line(firstDot, secondDot, [className: 'blue']);
这是行不通的。由于我不习惯他使用的语法,有人能帮我吗?我知道这一定很简单…插件要求a,而不是像您现在所做的那样,传递一个对象,如下所示:
$.line.defaults = {
className: 'jquery-line',
lineWidth: 1,
lineColor: '#000',
returnValues: false
};
var firstDot = $(this);
var secondDot = dots.eq( currentIndex + 1 + offset);
firstDot.y = firstDot.offset().top;
firstDot.x = firstDot.offset().left;
secondDot.y = secondDot.offset().top;
secondDot.x = secondDot.offset().left;
$.line(firstDot, secondDot);
$.line(firstDot, secondDot, {className: "blue"});
$.line(firstDot, secondDot, {className: 'jquery-line blue'})
或:
方括号表示参数是可选的,所以
$.line(fromPoint, toPoint[, options]);
这意味着您可以像这样调用函数
$.line(firstDot, secondDot);
或者
$.line(firstDot, secondDot, options);
你应该试着这样称呼它:
$.line.defaults = {
className: 'jquery-line',
lineWidth: 1,
lineColor: '#000',
returnValues: false
};
var firstDot = $(this);
var secondDot = dots.eq( currentIndex + 1 + offset);
firstDot.y = firstDot.offset().top;
firstDot.x = firstDot.offset().left;
secondDot.y = secondDot.offset().top;
secondDot.x = secondDot.offset().left;
$.line(firstDot, secondDot);
$.line(firstDot, secondDot, {className: "blue"});
$.line(firstDot, secondDot, {className: 'jquery-line blue'})
还请注意,该软件包包含一个用于lineColor
的选项,因此您可以这样称呼它
$.line(firstDot, secondDot, {lineColor: 'blue'})