Html.Kendo().DropDownList() ".text()" 无法正常工作
Html.Kendo().DropDownList() ".text()" not working properly
我有一个 Kendo DropdDownList,它似乎工作正常,它从 ViewData 中获取项目列表并完美显示它们。
.BindTo((System.Collections.IEnumerable)ViewData["modulos"])
.DataTextField("Codmodulo")
然后我调用控制器(通过 TypeScript)并尝试将所选项目的文本传递给他,如下所示:
Codmodulo: $("#funcionesDropDownList").text()
但出于某种原因,那总是 returns 一个空字符串 (""),而
Codmodulo: $("#funcionesDropDownList").val()
工作正常,给了我想要的价值。昨天这对我来说很好用。任何想法可能是错的?
英语不是我的第一语言,请随时询问更多详情。
.text()
Get the combined text contents of each element in the set of matched elements
和.val()
Get the current value of the first element in the set
DropdDownList
生成 input
html 元素并且输入没有内容。文本存储在值中。
如果你想从其他(非表单)标签中获取文本,你可以使用 text() 函数。
$("#funcionesDropDownList")
是下拉列表的隐藏输入 HTML 元素,它保存它的值。
text()
方法 returns 文本放置在您调用它的 DOM 元素内。因此,如果您为没有内部文本的元素调用它,例如:
<input id="funcionesDropDownList" value="abc" data-role="dropdownlist"
style="display: none;" />
您将得到空文本。
val()
方法返回元素值属性元素的值(在本例中为 abc),因此它 returns 正确值。
要使用 KendoUI API 获取下拉列表的值,您可以使用此代码:
var listValue = $("#funcionesDropDownList").data("kendoDropDownList").value();
您可以在 KendoUI site 上阅读有关 API 的信息。
我有一个 Kendo DropdDownList,它似乎工作正常,它从 ViewData 中获取项目列表并完美显示它们。
.BindTo((System.Collections.IEnumerable)ViewData["modulos"])
.DataTextField("Codmodulo")
然后我调用控制器(通过 TypeScript)并尝试将所选项目的文本传递给他,如下所示:
Codmodulo: $("#funcionesDropDownList").text()
但出于某种原因,那总是 returns 一个空字符串 (""),而
Codmodulo: $("#funcionesDropDownList").val()
工作正常,给了我想要的价值。昨天这对我来说很好用。任何想法可能是错的?
英语不是我的第一语言,请随时询问更多详情。
.text()
Get the combined text contents of each element in the set of matched elements
和.val()
Get the current value of the first element in the set
DropdDownList
生成 input
html 元素并且输入没有内容。文本存储在值中。
如果你想从其他(非表单)标签中获取文本,你可以使用 text() 函数。
$("#funcionesDropDownList")
是下拉列表的隐藏输入 HTML 元素,它保存它的值。
text()
方法 returns 文本放置在您调用它的 DOM 元素内。因此,如果您为没有内部文本的元素调用它,例如:
<input id="funcionesDropDownList" value="abc" data-role="dropdownlist"
style="display: none;" />
您将得到空文本。
val()
方法返回元素值属性元素的值(在本例中为 abc),因此它 returns 正确值。
要使用 KendoUI API 获取下拉列表的值,您可以使用此代码:
var listValue = $("#funcionesDropDownList").data("kendoDropDownList").value();
您可以在 KendoUI site 上阅读有关 API 的信息。