根据无线电按钮选择JavaScript中的值
在我的方案中,我想使用无线电按钮选择更改表值。
无线电按钮的代码
@Html.RadioButtonFor(m => m.Doctype1, new {
id = "doctype1", @onclick = "DocTypeSelect()"
}) @Html.Label("largedocs")
@Html.RadioButtonFor(m => m.Doctype2, new {
id = "doctype2", @onclick = "DocTypeSelect()"
}) @Html.Label("SmallDocs")
@Html.RadioButtonFor(m => m.Doctype3, new {
id = "doctype3", @onclick = "DocTypeSelect()"
}) @Html.Label("MediumDocs")
@Html.RadioButtonFor(m => m.Doctype4, new {
id = "doctype4", @onclick = "DocTypeSelect()"
}) @Html.Label("VerySmallDocs")
我为隐藏其他下拉值的逻辑编写了逻辑。通过使用我可以更改下拉列表并隐藏其他3个按钮。
<td id="DocTypes1">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes2">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes3">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes4">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
在JavaScript中,如果选择了一个特定的值,我想获得该值并在格式的表视图中显示。
现有代码始终仅获得一种DOC值。我不知道为什么???
funtion ChangeTypes(){
var docId=$("SelectDocType").val();
var docType=$("SelectDocType option:selected").text();
if(SelectDocType !="")
{
//my logic
}
实际上,当用户更改下拉值时,我需要获取数据。 我解决这个问题。
帮
In my scenario, I want to change the value of a table by using radio button selection.
Code for radio button
@Html.RadioButtonFor(m => m.Doctype1, new {
id = "doctype1", @onclick = "DocTypeSelect()"
}) @Html.Label("largedocs")
@Html.RadioButtonFor(m => m.Doctype2, new {
id = "doctype2", @onclick = "DocTypeSelect()"
}) @Html.Label("SmallDocs")
@Html.RadioButtonFor(m => m.Doctype3, new {
id = "doctype3", @onclick = "DocTypeSelect()"
}) @Html.Label("MediumDocs")
@Html.RadioButtonFor(m => m.Doctype4, new {
id = "doctype4", @onclick = "DocTypeSelect()"
}) @Html.Label("VerySmallDocs")
I wrote a logic for hide other dropdown values. By using I'm able to change the dropdown and hiding other 3 buttons.
<td id="DocTypes1">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes2">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes3">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
<td id="DocTypes4">
@Html.DropDownlistfor(m => m.Doctype, new selectlist(m.BigDocs, "Value", "Text", m.BigDocs), new {
@id = "SelectDocType",
@onchange = "ChangeTypes()"
})
In Javascript, If a particular value is selected I want to get that value and and display in a table view of format.
The existing code is always getting the one type of doc value only. I don't know why???
funtion ChangeTypes(){
var docId=$("SelectDocType").val();
var docType=$("SelectDocType option:selected").text();
if(SelectDocType !="")
{
//my logic
}
actually I need to get the data when a user change the dropdown values.
Help me to solve this..
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要找到所有下拉列表,则应:
应该给您所有下拉列表ID的匹配项,尽管它不是元素共享相同ID的最佳练习,如果您可以给他们一个唯一的ID,则可以找到它们,那么您可以找到它们所有使用类名称都
需要用于每个循环的所有名称,然后将每个元素项目的值从每个元素中获取
,但是如果您想让自己更轻松地生活,为什么不将价值传递给函数:
我希望这会有所帮助
if you need to find all the dropdowns then:
should give you all the dropdowns whos id's match, although its no best practice for elements to share the same id, if you can give them a unique id abut the same class then you can find them all using the class name
you will need to use a for each loop then to get the values out of each element item
but if you want to make life easier for yourself why not pass the value to the function like so:
I hope this helps