Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 Ui_Xhtml - Fatal编程技术网

Javascript 关于变更函数的jquery

Javascript 关于变更函数的jquery,javascript,jquery-ui,xhtml,Javascript,Jquery Ui,Xhtml,我有一个带有标题和细节部分的xhtml页面。标题包括过滤器,细节包括根据所选过滤器从db获取的数据。 根据我的要求,我的过滤器包含一个下拉列表,假设a和B有两个值,因此根据选择,我想禁用其他下拉列表 我添加了以下代码片段:- <script type="text/javascript"> $(function() { $('select').change(function() {

我有一个带有标题和细节部分的xhtml页面。标题包括过滤器,细节包括根据所选过滤器从db获取的数据。 根据我的要求,我的过滤器包含一个下拉列表,假设a和B有两个值,因此根据选择,我想禁用其他下拉列表

我添加了以下代码片段:-

<script type="text/javascript">
                $(function() {
                    $('select').change(function() {
                    alert($(this).val());
                    if($(this).val() == "A"){
                        $(document.getElementById('dataForm:listView:filterId:field10value1')).prop("disabled", true);
                        $(document.getElementById('dataForm:listView:filterId:field4value1')).prop("disabled", false);
                        $(document.getElementById('dataForm:listView:filterId:field6value1')).prop("disabled", false);
                    }else if($(this).val() == "R"){
                        $(document.getElementById('dataForm:listView:filterId:field10value1')).prop("disabled", false);
                        $(document.getElementById('dataForm:listView:filterId:field4value1')).prop("disabled", true);
                        $(document.getElementById('dataForm:listView:filterId:field6value1')).prop("disabled", true);
                    }else{
                        $(document.getElementById('dataForm:listView:filterId:field10value1')).prop("disabled", false);
                        $(document.getElementById('dataForm:listView:filterId:field4value1')).prop("disabled", false);
                        $(document.getElementById('dataForm:listView:filterId:field6value1')).prop("disabled", false);
                    }
                    })
                })
            </script>
这是第一次很好地工作。但当我点击apply获取数据时,下次它就不起作用了


请帮忙

如果您想要一个完整的jQuery解决方案,这将如下所示

工作示例:

HTML

发件人:

要使用任何元字符,如!$%&'*+,./:@[\]^{{124;}~作为名称的文字部分,必须用两个反斜杠转义:\\。例如,id=foo.bar的元素可以使用选择器$foo\\.bar

我还使用了开关结构。它做同样的事情,但我更喜欢它,因为我可以在未来种植它


您还将看到我使用了jQuery选择器而不是原始JavaScript方法。为了便于使用,我还将jQuery对象推送到它们自己的变量中。

应用程序获取数据的作用是什么?看起来它破坏了您的更改事件。$'select'。一旦更改,select,函数{…},您可以这样尝试吗。您还可以检查浏览器控制台以查看是否有任何jscript错误。在控制台中没有errorApply按钮,它将根据所选筛选器点击支持bean获取数据…我认为这会破坏更改事件..是否有其他方法来执行此操作我尝试了$'select'。一旦更改,选择,函数…它不工作..它也没有禁用在它工作正常之前工作的字段..现在我还有一个问题..我在应用过滤器之后出现了一个错误弹出..错误不在那里..但是弹出窗口不在那里..你能帮我得到只包含onchange函数的jquery js吗..我不想要剩下的我不知道你的意思。有屏幕截图吗?
<div class="ui-widget">
  <select>
    <option></option>
    <option>A</option>
    <option>R</option>
  </select>
</div>
<div class="ui-widget">
  <input id="dataForm:listView:filterId:field10value1" />
  <input id="dataForm:listView:filterId:field4value1" />
  <input id="dataForm:listView:filterId:field6value1" />
</div>
$(function() {
  $('select').change(function() {
    var selected = $(this).val();
    var field10 = $('#dataForm\\:listView\\:filterId\\:field10value1'),
      field04 = $('#dataForm\\:listView\\:filterId\\:field4value1'),
      field06 = $('#dataForm\\:listView\\:filterId\\:field6value1');
    switch (selected) {
      case "A":
        console.log("A Selected.");
        field10.prop("disabled", true);
        field04.prop("disabled", false);
        field06.prop("disabled", false);
        break;
      case "R":
        console.log("R Selected.");
        field10.prop("disabled", false);
        field04.prop("disabled", true);
        field06.prop("disabled", true);
        break;
      default:
        console.log("'' Selected.");
        field10.prop("disabled", false);
        field04.prop("disabled", false);
        field06.prop("disabled", false);
    }
  });
});