开发者

mark only one checkbox?

I have a pro开发者_如何学Goblem with checkbox. I have a list of checkbox, and I want to mark only one check and unmark other.

I want do that this in the same view , is it posible? How can I do that?

<div><input  type="checkbox" id="<%= id %>"  onchange='submit();'/> </div>

thanks


Sounds like you really need a radio button instead. Radio buttons are mutually exclusive if you give them the same name:

<input  type="radio" name="something" ... />
<input  type="radio" name="something" ... />

If you really want checkboxes you will have to write some JavaScript logic.


Use radio buttons, not checkboxes.

<div>
    foreach (var foo in model.Foos) {
        <input type="radio" name="foo" id="foo_@foo.Id" value="@foo.Id" /> 
        <label for="foo_@foo.Id">@foo.Value</label> <br />
    }
</div>

Something like that should create a list of radio buttons.

Also, why are you submitting when the selection is changed? You should be using jQuery to do any selection-based manipulation to the page on the client side.


You could use jQuery. on document.Ready you'll have to bind a change event on checkboxes to some function, then in your function you want to reset all other checkboxes. That's assuming you don't want to use radio buttons as suggested above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜