I want get the decimal value of @html.DisplayFor
with jQuery and pass with json.
我想要得到@html的十进制值。用jQuery显示并使用json传递。
I try with:
我尝试:
var debtor = $("#debtor").val();
but I gain debtor
and not the decimal value.
但我得到的是债务人而不是小数。
<span class="debtorVal" style="color: red">
@Html.DisplayFor(model => model.Debtor, new { id = "debtor" })
</span>
The model => model.Debtor
is decimal number
= >模型模型。债务人是小数
3 个解决方案
#1
0
Try simple html tag:
试着简单的html标签:
<span class="debtorVal" style="color: red">
<span id="debtor">@model.Debtor</span>
</span>
#2
0
I gess you should change your markup to this:
我知道你应该把你的加价改为:
<span id="debtor" class="debtorVal" style="color: red">
@Html.DisplayFor(model => model.Debtor)
</span>
Note that i place id
attribute to span
tag like @Stephen Muecke advice you.
注意,我将id属性设置为span标签,就像@Stephen Muecke建议的那样。
And you can get value like this with jQuery now:
现在你可以用jQuery得到这样的值:
var debtor = $("#debtorVal").text();
And solution with pure js:
和纯js解决方案:
var debtor = document.getElementById("debtor").innerHTML;
#3
0
For getting value of span
, div
, p
use .text();
instead of .val();
为了获取span的值,div, p使用。text();而不是.val();
var debtor = $(".debtorVal").text();
#1
0
Try simple html tag:
试着简单的html标签:
<span class="debtorVal" style="color: red">
<span id="debtor">@model.Debtor</span>
</span>
#2
0
I gess you should change your markup to this:
我知道你应该把你的加价改为:
<span id="debtor" class="debtorVal" style="color: red">
@Html.DisplayFor(model => model.Debtor)
</span>
Note that i place id
attribute to span
tag like @Stephen Muecke advice you.
注意,我将id属性设置为span标签,就像@Stephen Muecke建议的那样。
And you can get value like this with jQuery now:
现在你可以用jQuery得到这样的值:
var debtor = $("#debtorVal").text();
And solution with pure js:
和纯js解决方案:
var debtor = document.getElementById("debtor").innerHTML;
#3
0
For getting value of span
, div
, p
use .text();
instead of .val();
为了获取span的值,div, p使用。text();而不是.val();
var debtor = $(".debtorVal").text();