【问题标题】:calling input value using jquery val() method not working after space in my MVC View?使用 jquery val() 方法调用输入值在我的 MVC 视图中的空格后不起作用?
【发布时间】:2015-09-28 08:01:18
【问题描述】:

这是我的代码:

在我的 MVC 视图中:

  @
  {
  var datefrom = Model.Vehicle.First().DateFrom.ToString("MMMM    yyyy")
  };

在我的 AjaxBeginForm 中:

    {
     <input type="hidden" id="vehicledatefrom" value=@datefrom/>
    }

我的 jquery:

          var datefromto= $('#vehicledatefrom').val() ;



   After debugging with break point, the datefrom value is = " July 2006";
   But when I am calling the val() in jquery I am getting only "July".
   What's the wrong in my code why I am not getting complete value "July 2006";
   val() is not taking after the space why any suggestions thanks

【问题讨论】:

    标签: javascript c# jquery asp.net-mvc model-view-controller


    【解决方案1】:

    那是因为您没有使用quotes 封闭value 属性。

    在遇到一个它认为是结束的空间之前,它似乎只取了值的第一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      相关资源
      最近更新 更多