Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
在jQuery中定位下一个类时面临的问题_Jquery - Fatal编程技术网

在jQuery中定位下一个类时面临的问题

在jQuery中定位下一个类时面临的问题,jquery,Jquery,请看一下这个spinet,让我知道为什么我不能针对第一个。帮助阻止输入附近的现有功能 正如你所看到的,我已经试过了 $(this).parent().find('help-block').html('Name Field Can\'t Be Empty!'); $(this).closest('help-block').html('Name Field Can\'t Be Empty!'); $(this).parent().next('.help-block').html('Name Fi

请看一下这个spinet,让我知道为什么我不能针对第一个。帮助阻止输入附近的现有功能

正如你所看到的,我已经试过了

$(this).parent().find('help-block').html('Name Field  Can\'t Be Empty!');
$(this).closest('help-block').html('Name Field  Can\'t Be Empty!');
$(this).parent().next('.help-block').html('Name Field  Can\'t Be Empty!');
但仍然无法针对该段落

函数txtInputelem{ var inputData=$.trimelem.val; 如果输入数据=={ $this.parent.find'help-block'.html'Name字段不能为空!'; $this.closest'help-block'.html'Name字段不能为空!'; $this.parent.next'.help block'.html'名称字段不能为空!'; } } $.btn-default.onclick,函数{ 如果txtInput$'name'{console.logIt有效;} }; 名称

help


Text将您的函数更改为使用elem,而不是此函数:

function txtInput(elem) {
        var inputData = $.trim(elem.val());
        if (inputData == "") {
          $(elem).parent().find('help-block').html('Name Field  Can\'t Be Empty!');
          $(elem).closest('help-block').html('Name Field  Can\'t Be Empty!');
          $(elem).parent().next('.help-block').html('Name Field  Can\'t Be Empty!');
        }
    }

仅仅通过做那个改变,它现在就起作用了。这是一个有效的例子。

将$this更改为$elem-这指的是按钮两件事,1、确保您的“查找”和“最近的”使用了正确的选择器,因为您缺少一个选项。他们中的一些人。2.除了做这个,家长。。。做$elem.parent。。。