Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么jsHint会警告我:';(var)已定义但从未使用';?_Javascript_Jquery_Jshint - Fatal编程技术网

Javascript 为什么jsHint会警告我:';(var)已定义但从未使用';?

Javascript 为什么jsHint会警告我:';(var)已定义但从未使用';?,javascript,jquery,jshint,Javascript,Jquery,Jshint,我使用CodeKit在我的脚本上运行jsHint,并最小化它们,我想了解以下错误: // create a next button for each text input and wire it for nextQ()! var next = $('<a class="button next">Next</a>') .on( 'click', function() { nextQ( $(this) );

我使用CodeKit在我的脚本上运行jsHint,并最小化它们,我想了解以下错误:

    // create a next button for each text input and wire it for nextQ()!
    var next = $('<a class="button next">Next</a>')
        .on( 'click', function() {
            nextQ( $(this) );
        })
        .insertAfter( $questions.find(':text') );
//为每个文本输入创建下一个按钮,并将其连接到nextQ()!
var next=$(“next”)
.on('click',function(){
nextQ($(本));
})
.insertAfter($questions.find(“:text”);
jsHint警告:

next已定义但从未使用


假设每个页面加载时元素都是insertedAfter(),这是jsHint的限制,还是我做错了什么?我的jQuery非常基本,我想从错误中学习

好吧,您正在定义一个回调,它不需要分配给变量;您可以简单地执行以下操作:

$('<a class="button next">Next</a>')
    .on( 'click', function() {
        nextQ( $(this) );
    })
.insertAfter( $questions.find(':text') );
$(“下一步”)
.on('click',function(){
nextQ($(本));
})
.insertAfter($questions.find(“:text”);

所以下一步没什么用。

好吧,您正在定义一个回调,它不需要分配给变量;您可以简单地执行以下操作:

$('<a class="button next">Next</a>')
    .on( 'click', function() {
        nextQ( $(this) );
    })
.insertAfter( $questions.find(':text') );
$(“下一步”)
.on('click',function(){
nextQ($(本));
})
.insertAfter($questions.find(“:text”);

所以next没有任何作用。

next变量是不必要的,因为
.insertAfter()
.on()的返回值上被调用。除非您要在下一个
上调用某些内容,否则您可以执行以下操作:

$('<a class="button next">Next</a>')
    .on( 'click', function() {
        nextQ( $(this) );
    })
    .insertAfter( $questions.find(':text') );
$(“下一步”)
.on('click',function(){
nextQ($(本));
})
.insertAfter($questions.find(“:text”);

无需使用
下一个
变量,因为
.insertAfter()
.on()
的返回值上被调用。除非您要在下一个
上调用某些内容,否则您可以执行以下操作:

$('<a class="button next">Next</a>')
    .on( 'click', function() {
        nextQ( $(this) );
    })
    .insertAfter( $questions.find(':text') );
$(“下一步”)
.on('click',function(){
nextQ($(本));
})
.insertAfter($questions.find(“:text”);

您正在定义
下一步
。您在哪里使用它?为什么您的代码中甚至有“var next=?此处不需要它。您正在定义
next
。您在哪里使用它?为什么您的代码中甚至有“var next=?这里不需要它。