2014-01-29 62 views
0

情景的Javascript块在Chrome和IE浏览器不会呈现

我正在开发一种报告生成的。用户从select中选择报告并单击按钮。具有所需参数的表单是动态创建和呈现的。一些参数呈现为select s,绑定到db表。

  1. 如何的形式被称为:

    var data = { 'ReportId': $('#Reports option:selected').val() }; 
    $.ajax({ 
        type: 'GET', 
        url: '/statistics/ReportBuilder/GetReportParameters', 
        dataType: 'text', 
        data: data, 
        success: function(data){ 
         $('#divReportParameters').html(data); 
        }, 
        complete: function(){ 
         mkNamespace.utils.dom.hideLoader($('#content')); 
        } 
    }); 
    
  2. GetReportParameters.cshtml。的形式是一个简单的容器由一个视图:

     @model ReportBuilderModel 
         <div> 
          <h3>@Model.Report.Label</h3> 
         </div> 
         <div> 
          <form id='frmReportParameters' action='@Url.Action("GetReport")' method="post"> 
           @Html.Partial("~/Views/Shared/Controls/_ParametricForm.cshtml", Model.Parameters) 
           <input type = "hidden" id="reportId" name="reportId" value="@Model.Report.Id" /> 
           <input id="btnGetReport" type="button" value="Estrai Report" /> 
          </form> 
         </div> 
    
  3. _ParametricForm.cshtml。实际参数列表使用局部视图_ParametricForm呈现。该部分由两部分组成。第一部分呈现<table>,参数集合上的循环,创建一行并将相应的GUI元素放入行中。第二部分使用onchange事件处理程序呈现<script>块。

    @model FormParameterCollection 
    
        <table class="tableForm parametricForm"> 
        @foreach (FormParameter par in Model) { 
         <tr> 
          <td class="fieldLabel">@par.Label</td> 
          <td class="fieldInput"> 
           @switch(par.Type){ 
            case FormParameterType.Input: 
             <input name="@par.Name" type="text" class="fieldText" /> 
             break; 
            case FormParameterType.Select: 
             <select name="@par.Name" class="fieldSelect"> 
             @if (!string.IsNullOrWhiteSpace(par.DefaultLabel) || !string.IsNullOrWhiteSpace(par.DefaultValue)) 
             { 
              <option value="@par.DefaultValue" data-tag="">@par.DefaultLabel</option> 
             } 
             @foreach (DataSourceItem item in DataSourceManager.Current[par.DataSource]) 
             { 
              <option value="@item.Value" data-tag="@item.Tag">@item.Label</option> 
             } 
             </select> 
             break; 
            case FormParameterType.MultiSelect: 
             <select name="@par.Name" class="fieldSelect" multiple="multiple" size="6"> 
             @if (!string.IsNullOrWhiteSpace(par.DefaultLabel) || !string.IsNullOrWhiteSpace(par.DefaultValue)) 
             { 
              <option value="@par.DefaultValue" data-tag="">@par.DefaultLabel</option> 
             } 
             @foreach (DataSourceItem item in DataSourceManager.Current[par.DataSource]) 
             { 
              <option value="@item.Value" data-tag="@item.Tag">@item.Label</option> 
             } 
             </select> 
             break; 
            case FormParameterType.Date: 
             @Html.JQueryUI().Datepicker(par.Name, DateTime.Now) 
             break; 
            default: 
             <input name="@par.Name" type="text" class="fieldText" /> 
             break; 
           } 
          </td> 
         </tr> 
        } 
        </table> 
        <script type="text/javascript"> 
         //dynamically bind the onchange events of the parametes 
         $(document).ready(function(){ 
          @foreach (FormParameter par in Model) { 
          <text> 
           @if(!String.IsNullOrEmpty(par.ParentParameter)){  //the onchange event is bound for the 'parent related' parameters (e.g. shop & categories) 
            <text> 
            $('.tableForm.parametricForm').on('change', '[name="@par.ParentParameter"]', function (e) { 
             var parentId = e.target.value; 
    
             $('[name="@par.Name"] > option').hide(); 
             $('[name="@par.Name"] > option').filter(function() { 
              var tag = $(this).attr('data-tag'); 
              return (tag == '' ? true : (JSON.parse($(this).attr('data-tag'))['@par.ParentParameter'] == parentId) || (parentId == '')); 
             }).show(); 
            }); 
            </text> 
           } 
          </text> 
          } 
         }); 
    
         //bind jQueryUI functions after the ajax call 
         $('.tableForm').jQueryUIHelpers(); 
        </script> 
    

问题

现在,不介意的所有细节。所有这些东西完美运行在Firefox上。

在Chrome e IE中,_ParametricForm部分中的<script>块在响应中正确返回(使用调试器进行检查),但不会执行onchange事件处理程序。

因此,问题不在于部分视图逻辑,因为在所有浏览器中都正确地创建了响应。但这个问题似乎与浏览器引擎有关。

如何解决这个问题?

回答

0

您设置的数据类型为文本,所以它要把它当作文本和不处理它。设置为“html”。

0

如果它的表单域那么keyup/keypress是否合适?如果需要更改,请尝试focusout比较当前和以前的更改值。

onchange只在控件模糊时触发。 (source

相关问题