Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 Jquery代码在站点上不起作用,但在小提琴中起作用_Javascript_Jquery - Fatal编程技术网

Javascript Jquery代码在站点上不起作用,但在小提琴中起作用

Javascript Jquery代码在站点上不起作用,但在小提琴中起作用,javascript,jquery,Javascript,Jquery,我有一个输入列表,其中有几个父div,然后在每个父项下有多个子复选框。只有1级子级。(请参阅下面的链接) 在每个父项下,我都有复选框(必须使用复选框,而不是单选按钮),并且应该只允许在每个父项中选择一个子项 我在一个小提琴上使用了下面的代码-它工作正常,但是将它应用到应用程序是失败的,但是chrome没有显示错误来调试正在发生的事情 $('input[type=checkbox]').click(function () { var checkedState = $(this).attr(

我有一个输入列表,其中有几个父div,然后在每个父项下有多个子复选框。只有1级子级。(请参阅下面的链接)

在每个父项下,我都有复选框(必须使用复选框,而不是单选按钮),并且应该只允许在每个父项中选择一个子项

我在一个小提琴上使用了下面的代码-它工作正常,但是将它应用到应用程序是失败的,但是chrome没有显示错误来调试正在发生的事情

$('input[type=checkbox]').click(function () {
    var checkedState = $(this).attr("checked");
    $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
    $(this).attr("checked", checkedState);
});
以下是我正在努力实现的一个工作示例:

在这里可以找到不工作的dev站点:(我知道页面加载很慢),您会注意到所有复选框都可以选中,这是我试图避免的

作为旁注,人们提到它不在DOM中。但是一个包裹在

$(document).ready(function() { 
下面是dev站点上的完整脚本

<script>

$(document).ready(function() {

//Update the is in stock flag, by altering the criteria input fields.
$("input[[id*='chkInStock']]").change(function() {
    if ($("input[[id*='chkInStock']]").prop('checked') == true) $("input[[id*='nbs-min']]").val('1');
    if ($("input[[id*='chkInStock']]").prop('checked') == false) $("input[[id*='nbs-min']]").val('0');
});

if ('[Settings:chktextsearch]'=='False')
{
    // ALL Text search is turned off in the settings, so use JS to update the "disabledsearchtokens" for all text search tokens -->
    var disabledlist = $("input[[id*='disabledsearchtokens']]").val();
    if (disabledlist.indexOf('search0;') == -1) disabledlist = disabledlist + 'search0;';
    if (disabledlist.indexOf('search1;') == -1) disabledlist = disabledlist + 'search1;';
    if (disabledlist.indexOf('search2;') == -1) disabledlist = disabledlist + 'search2;';
    if (disabledlist.indexOf('search3;') == -1) disabledlist = disabledlist + 'search3;';
    if (disabledlist.indexOf('search4;') == -1) disabledlist = disabledlist + 'search4;';
    if (disabledlist.indexOf('search5;') == -1) disabledlist = disabledlist + 'search5;';
    if (disabledlist.indexOf('search6;') == -1) disabledlist = disabledlist + 'search6;';
    if (disabledlist.indexOf('search7;') == -1) disabledlist = disabledlist + 'search7;';
    if (disabledlist.indexOf('search8;') == -1) disabledlist = disabledlist + 'search8;';
    // Update disabled fields to the postback field -->
    $("input[[id*='disabledsearchtokens']]").val(disabledlist);
   }

   $('input[type=checkbox]').click(function () {
      var checkedState = $(this).attr("checked");           

     $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
   $(this).attr("checked", checkedState);
    });

    $('label').each(function () {
       var $this = $(this);
      $this.html($this.text().replace(/^(\.+)/g, '<span style="display:none">$1</span><span     class="Child">'));
         });
     });

    </script>

$(文档).ready(函数(){
//通过更改条件输入字段来更新库存标志。
$(“输入[[id*='chkInStock']])。更改(函数(){
if($(“输入[[id*='chkInStock']]).prop('checked')==true)$(“输入[[id*='nbs-min']]).val('1');
if($(“输入[[id*='chkInStock']]).prop('checked')==false)$(“输入[[id*='nbs-min']]).val('0');
});
如果('[Settings:chktextsearch]'=='False')
{
//在设置中关闭所有文本搜索,因此使用JS更新所有文本搜索标记的“disabledsearchtokens”->
var disabledlist=$(“输入[[id*='disabledsearchtokens']])。val();
如果(disabledlist.indexOf('search0;'))=-1)disabledlist=disabledlist+'search0;';
如果(disabledlist.indexOf('search1;'))=-1)disabledlist=disabledlist+'search1;';
如果(disabledlist.indexOf('search2;'))=-1)disabledlist=disabledlist+'search2;';
如果(disabledlist.indexOf('search3;'))=-1)disabledlist=disabledlist+'search3;';
如果(disabledlist.indexOf('search4;'))=-1)disabledlist=disabledlist+'search4;';
如果(disabledlist.indexOf('search5;'))=-1)disabledlist=disabledlist+'search5;';
如果(disabledlist.indexOf('search6;'))=-1)disabledlist=disabledlist+'search6;';
如果(disabledlist.indexOf('search7;'))=-1)disabledlist=disabledlist+'search7;';
如果(disabledlist.indexOf('search8;'))=-1)disabledlist=disabledlist+'search8;';
//将禁用的字段更新到回发字段-->
$(“输入[[id*='disabledsearchtokens']])val(disabledlist);
}
$('input[type=checkbox]')。单击(函数(){
var checkedState=$(this.attr(“checked”);
$(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked')。removeAttr(“checked”);
$(this.attr(“checked”,checkedState);
});
$('label')。每个(函数(){
var$this=$(this);
$this.html($this.text().replace(/^(\.+)/g,$1');
});
});

任何帮助都将不胜感激。

可能是因为您没有将代码包装到DOM就绪处理程序中,而该处理程序已经为您完成了这项工作,请尝试执行以下操作:

$(function() {
    $('input[type=checkbox]').click(function () {
        var checkedState = $(this).attr("checked");
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
        $(this).attr("checked", checkedState);
    });
});

可能是因为您没有将代码包装到DOM就绪处理程序中,
jsFiddle
已经为您完成了这项工作,请尝试执行以下操作:

$(function() {
    $('input[type=checkbox]').click(function () {
        var checkedState = $(this).attr("checked");
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
        $(this).attr("checked", checkedState);
    });
});

可能是因为您没有将代码包装到DOM就绪处理程序中,
jsFiddle
已经为您完成了这项工作,请尝试执行以下操作:

$(function() {
    $('input[type=checkbox]').click(function () {
        var checkedState = $(this).attr("checked");
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
        $(this).attr("checked", checkedState);
    });
});

可能是因为您没有将代码包装到DOM就绪处理程序中,
jsFiddle
已经为您完成了这项工作,请尝试执行以下操作:

$(function() {
    $('input[type=checkbox]').click(function () {
        var checkedState = $(this).attr("checked");
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
        $(this).attr("checked", checkedState);
    });
});

在阅读了您的评论后,我认为这可能有效:

$(document).ready(function(){
    $('input[type=checkbox]').click(function () {
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");            
        $(this).attr("checked", "checked");            
    });
});

在阅读了您的评论后,我认为这可能有效:

$(document).ready(function(){
    $('input[type=checkbox]').click(function () {
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");            
        $(this).attr("checked", "checked");            
    });
});

在阅读了您的评论后,我认为这可能有效:

$(document).ready(function(){
    $('input[type=checkbox]').click(function () {
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");            
        $(this).attr("checked", "checked");            
    });
});

在阅读了您的评论后,我认为这可能有效:

$(document).ready(function(){
    $('input[type=checkbox]').click(function () {
        $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");            
        $(this).attr("checked", "checked");            
    });
});

可能有两个问题

  • 代码不在dom就绪处理程序中
  • 使用attr()而不是.prop()来设置选中的属性
  • 所以试试看

    jQuery(function ($) {
        $('input[type=checkbox]').click(function () {
            //if the markup in the jsfiddle is same as the one in your page then try
            $(this).closest('table').find('input[type=checkbox]:checked').not(this).prop("checked", false);
        });
    })
    
    注意:不要使用chained.parent()调用,而是使用.closest()调用


    演示:

    可能有两个问题

  • 代码不在dom就绪处理程序中
  • 使用attr()而不是.prop()来设置选中的属性
  • 所以试试看

    jQuery(function ($) {
        $('input[type=checkbox]').click(function () {
            //if the markup in the jsfiddle is same as the one in your page then try
            $(this).closest('table').find('input[type=checkbox]:checked').not(this).prop("checked", false);
        });
    })
    
    注意:不要使用chained.parent()调用,而是使用.closest()调用


    演示:

    可能有两个问题

  • 代码不在dom就绪处理程序中
  • 使用attr()而不是.prop()来设置选中的属性
  • 所以试试看

    jQuery(function ($) {
        $('input[type=checkbox]').click(function () {
            //if the markup in the jsfiddle is same as the one in your page then try
            $(this).closest('table').find('input[type=checkbox]:checked').not(this).prop("checked", false);
        });
    })
    
    注意:不要使用chained.parent()调用,而是使用.closest()调用


    演示:

    可能有两个问题

  • 代码不在dom就绪处理程序中
  • 使用attr()而不是.prop()来设置选中的属性
  • 所以试试看

    jQuery(function ($) {
        $('input[type=checkbox]').click(function () {
            //if the markup in the jsfiddle is same as the one in your page then try
            $(this).closest('table').find('input[type=checkbox]:checked').not(this).prop("checked", false);
        });
    })
    
    注意:不要使用chained.parent()调用,而是使用.closest()调用


    演示:

    我能想到的唯一原因是您的JS代码执行发生在DOM构建之前。将代码放入
    $(文档).ready(处理程序)
    中。查看jquery文档了解更多详细信息

    我能想到的唯一原因是您的JS代码执行发生在DOM构建之前。将代码放入
    $(文档).ready(处理程序)
    中。查看jquery文档了解更多详细信息

    我能想到的唯一原因是您的JS代码执行发生在DOM构建之前。将代码放入
    $(文档).ready(处理程序)
    中。查看jquery文档了解更多详细信息

    我能想到的唯一原因是您的JS代码执行发生在DOM构建之前。将代码放入
    $(文档).ready(处理程序)
    中。查看jquery文档以了解更多详细信息

    尝试以下方法:

    $(document).ready( function(){
        $('input[type=checkbox]').click(function () {
            var checkedState = $(this).attr("checked");
            $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
            $(this).attr("checked", checkedState);
        });
    });
    
    试试这个:

    $(document).ready( function(){
        $('input[type=checkbox]').click(function () {
            var checkedState = $(this).attr("checked");
            $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
            $(this).attr("checked", checkedState);
        });
    });
    
    试试这个:

    $(document).ready( function(){
        $('input[type=checkbox]').click(function () {
            var checkedState = $(this).attr("checked");
            $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
            $(this).attr("checked", checkedState);
        });
    });
    
    试试这个:

    $(document).ready( function(){
        $('input[type=checkbox]').click(function () {
            var checkedState = $(this).attr("checked");
            $(this).parent().parent().parent().parent().parent().find('input[type=checkbox]:checked').removeAttr("checked");
            $(this).attr("checked", checkedState);
        });
    });
    

    我认为这里的问题是一些选择器没有选择目标元素,或者如果您有正确的选择器(因为我不知道代码上实际发生了什么),请尝试我为您编写的这个简单代码。得到t