本文介绍了通过jQuery的变化DisplayFor文/值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要这个displayfor从使用jquery更新它的值。我试过.VAL()和的.text(),但既不工作,有没有特殊的方式,为显示器做到这一点,我需要它,并保持作为显示器。还可以在风格不适合显示设置?我从来没有得到工作,它为TextboxFor。感谢您的任何提示。

 估计时间:@ Html.DisplayFor(型号=> model.EstimatedTime,新{@class =TitleEstTimeClass,@style =COLOR:绿色})
      $(。TitleEstTimeClass)VAL(导致[1]);


解决方案

DisplayFor 生成一个标记HTML标记<标签ID =身份识别码类=MyClass的>有的文字< /标签> (错误)

修改

我错了,还以为你在使用 LabelFor 帮手。在 DisplayFor 辅助输出没有HTML标记(如标签或span标记)。如果你想这与 DisplayFor 辅助工作,您将需要一个<$ C包住 DisplayFor 标签$ C>&LT;跨度&GT; 或类似像下面的内容:

 &LT;跨度类=TitleEstTimeClass的风格=颜色:绿色&GT;
   @ Html.DisplayFor(型号=&GT; model.EstimatedTime)
&LT; / SPAN&GT;

鉴于此,请尝试使用像下面的的.html() JQuery的财产 - 这真的是不超过更新在格或跨文本中的不同:

  $(。TitleEstTimeClass)HTML(结果[1]);

另外,还要确保您的JQuery的通话中相应的&LT;脚本&GT;&LT; / SCRIPT&GT; 标签和你调用的函数实际上是被解雇。我不知道如果上述code是直接从您的项目或只是片段,但正如上面写的,什么都不会发生。

I need this displayfor to update its value from using jquery. I tried .val() and .text() but neither worked, is there a special way to do this for Displays, I need it to be and stay as a Display. Also can the style not be set for Displays? I never could get that to work, it works for TextboxFor. Thanks for any tips.

 Estimated Time: @Html.DisplayFor(model => model.EstimatedTime, new { @class = "TitleEstTimeClass", @style = "color: green" })


      $(".TitleEstTimeClass").val(result[1]);
解决方案

DisplayFor generates a label HTML tag <label id="myId" class="myClass">Some Text</label>. (INCORRECT)

EDIT

I was wrong and thought you were using the LabelFor helper. The DisplayFor helper outputs no HTML markup (like a label or span tag). If you want this to work with the DisplayFor helper, you will need to wrap the DisplayFor tag with a <span> or something similar like below:

<span class="TitleEstTimeClass" style="color: green">
   @Html.DisplayFor(model => model.EstimatedTime)
</span>

Given this, try using the .html() JQuery property like below - it really is no different than updating the text in div or span:

$(".TitleEstTimeClass").html(result[1]);

Also, be sure that your JQuery call is in the appropriate <script></script> tags and that the function that you are calling is actually being fired. I am not sure if the above code is straight from your project or just snippets, but as written above, nothing will happen.

这篇关于通过jQuery的变化DisplayFor文/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 12:20