@Html.checkboxfor - Get checkbox value using id

随声附和 提交于 2019-12-23 03:28:08

问题


In my application, user has a choice to check or uncheck a field "Right". I could able to set the model values to the checkbox using @html.checkboxfor

 @Html.CheckBoxFor(x => x.Right, new { id="right"})

Can someone help me how to get the value using the id. For now i am using $("#right").val() to get the value. But it is not working. Someone please help me to solve this issue.


回答1:


Use:

 $("#right").prop('checked') 

OR

$("#right").is(":checked")



回答2:


You can get the checked checkbox values like this

$('input:checkbox[name=right]').each(function() {
if($(this).is(':checked'))
  alert($(this).val());});

Please check this Link. It can be helpful




回答3:


This is working for me to get @Html.CheckBoxFor status using JS .. Thanks kikyalex

@Html.CheckBoxFor(model => model.IA.InProcess, new { @id = "cbinPro" })

alert($("#cbinPro").is(":checked"));


来源:https://stackoverflow.com/questions/23007423/html-checkboxfor-get-checkbox-value-using-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!