2

我有一个奇怪的问题。添加对 Jquery 1.7.2 的支持时,我无法在表单中的 textareas 中添加换行符。当我单击,输入时,没有任何反应。

我在jquery中摆弄了源代码,发现如果我注释掉以下代码(在第4845行)

for ( var type in Expr.match ) {
    Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
    Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
}

添加换行符的能力已恢复。我没有看到其他人有这个问题,所以我猜还有其他事情发生。但是,我的问题是:上面代码的目的是什么(我不是很懂 javascript),删除它会带来任何风险吗?我只想删除代码并恢复 textareas 的换行功能,但不想在不知不觉中破坏网站。我确实注意到,在这样做之后,我在 js 控制台中看到了一个错误:

Uncaught TypeError: Cannot call method 'exec' of undefined -- jquery.js:4185

任何帮助将不胜感激!


这是一些代码示例。的HTML:

    <form class="form-input" method="post">
  <fieldset>
    <ol>
      <li>
          <label for="activity_type_id">Activity Type&nbsp;<em>*</em></label>
          <select name="activity_type_id"><option value="17" label="Call">Call</option><option value="23" label="Connectivity Meeting">Connectivity Meeting</option><option value="22" label="Conversation">Conversation</option><option value="16" label="Email (incoming)">Email (incoming)</option><option value="15" label="Email (outgoing)">Email (outgoing)</option><option value="19" label="Implementation Notes">Implementation Notes</option><option value="20" label="Meeting Minutes">Meeting Minutes</option><option value="18" label="Task">Task</option><option value="21" label="Tip / Unusual Attribute">Tip / Unusual Attribute</option></select>      </li>    
      <li>
          <label for="summary">Summary&nbsp;<em>*</em></label>
          <input size="40" maxlength="80" id="summary" name="summary" value=""/>
      </li>   
      <li>
          <label for="details">Details&nbsp;</label>
          <textarea class="wide" name="details" id="details" rows="10" columns="80"></textarea>
      </li>
          </ol>
  </fieldset>
  <input id="submit" name="addactivity" value="Add Activity" type="submit" />
  </form>

以及其他插件中不包含的 javascript:

<script>
// Dynamic lookup of C2 companies
$(document).ready(function ()
{
  $(window).keydown(function(event)
  {
    if(event.keyCode == 13) 
    {
      event.preventDefault();
      return false;
    }
  });
  $("#search_input").autocomplete(
  {
    source: function(request,response)
    {
      $("#loading-search").show();
      $("#no-results").hide();
      $.getJSON("/services/json/cust_search.php",request,function(data) 
      {
        response(data);
        $("#loading-search").hide();
        if (data.length == 0)
        {
          $("#no-results").show();
        } else
        {
          $("#no-results").hide();
        }
      });
    },                                              
    minLength: 3,
    select: function(event,ui)
    {
      $("#search_input").hide();
      $("#search_input").val(ui.item.value);
      $("#search_source").val(ui.item.source);
      $("#search-form").submit();
    } 
  });
});
</script> 
<script type="text/javascript">
//---------------------------------------------------------------------------
//  Hide all the submenus on start.  When a non-expanded menu is clicked,
//  expand that menu while collapsing the menu above it.  If a menu is 
//  clicked when its expanded, collapse.
//---------------------------------------------------------------------------
$(function() 
{
//  $("dd:not(:first)").hide();
  $("dd").hide();
  $("#menu-nexmark").slideDown("fast");
  $("dt a").click(function() 
  {
    var curr_dd = $(this).parent().next();
     if (curr_dd.css("display") != "none")
    {
      $("dd:visible").slideUp("medium");
      return;
    }
    $("dd:visible").slideUp("slow");
    curr_dd.slideDown("slow");
    return false;
  });
});
</script>
4

1 回答 1

2

问题是这段代码:

$(window).keydown(function(event)
  {
    if(event.keyCode == 13) 
    {
      event.preventDefault();
      return false;
    }
  });

将其设置为仅引用它所影响的 div(我们希望禁用单击输入功能的自动完成搜索菜单),在其他任何地方恢复换行功能:

$("#somediv").keydown(function(event)
  {
    if(event.keyCode == 13) 
    {
      event.preventDefault();
      return false;
    }
  });
于 2012-06-13T18:03:45.340 回答