我正在使用JSLint工具来确保我的JavaScript是"严格的".
我收到以下错误但不明白如何解决它:
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype
Run Code Online (Sandbox Code Playgroud)
对于以下代码:
for (var i in keypairs) {
...
}
Run Code Online (Sandbox Code Playgroud)
任何人都有任何想法如何解决它的JavaScript"严格",并且不会被JSLint标记
我尝试过这种不同的方式,但似乎没有任何效果.这是我目前拥有的:
var vis = d3.select("#chart").append("svg")
.attr("width", 1000)
.attr("height", 667),
scaleX = d3.scale.linear()
.domain([-30,30])
.range([0,600]),
scaleY = d3.scale.linear()
.domain([0,50])
.range([500,0]),
poly = [{"x":0, "y":25},
{"x":8.5,"y":23.4},
{"x":13.0,"y":21.0},
{"x":19.0,"y":15.5}];
vis.selectAll("polygon")
.data(poly)
.enter()
.append("polygon")
.attr("points",function(d) {
return [scaleX(d.x),scaleY(d.y)].join(",")})
.attr("stroke","black")
.attr("stroke-width",2);
Run Code Online (Sandbox Code Playgroud)
我假设这里的问题是我将点数据定义为单个点对象的数组的方式,或者与我如何编写函数的方式有关 .attr("points",...
我一直在网上寻找一个如何绘制简单多边形的教程或示例,但我似乎无法找到它.
我正在编写一个jquery UI小部件,它简单地包装了bootstrap popover插件.在小部件中你可以传递选项'singular',如果传入它,那么它应该调用插件的所有其他实例的函数.
就像是
$('#one').myWidget();
$('#two').myWidget();
$('#three').myWidget();
$('#four').myWidget();
$('#one').myWidget('show'); //stuff from widget one is now visible
$('#two').myWidget('show'); //stuff from widget one and two are now visible
$('#three').myWidget('show'); //stuff from widget one, two and three are now visible
$('#two').myWidget('hide'); //stuff from widget one and three are now visible
$('#four').myWidget('show', {singular:true}); //stuff from widget four is now visible
Run Code Online (Sandbox Code Playgroud)
所以,我认为show函数看起来像:
show: function(options){
options = options || {};
if(options.singular){
var instances = '????'; // how do I get all instances?
$.each(instances, function(i, o){
o.myWidget('hide'); …Run Code Online (Sandbox Code Playgroud) 我有两个具有相同名称的文本框,control_text但它们的值不同.我想使用jQuery将所有文本框值存储在数组中.
HTML
<input type="text" name="control_text" placeholder="Text Label Image" class="required" id="control_text" value="firstvalue" />
<input type="text" name="control_text" placeholder="Text Label Image" class="required" id="control_text" value="secondvalue" />
Run Code Online (Sandbox Code Playgroud)
JavaScript的
var test_arr = $("input[name='control_text']");
$.each(test_arr, function(i, item) {
// i = index, item = element in array
alert($(item).val());
});
Run Code Online (Sandbox Code Playgroud)
上面的代码分别显示了文本框的值.我不想单独提醒这些值,我想用逗号分隔符同时提醒两者
(firstvalue, secondvalue).任何帮助表示赞赏.