【问题标题】:mvc .net form submit checkbox-label not working in Internet Explorermvc .net 表单提交复选框标签在 Internet Explorer 中不起作用
【发布时间】:2015-05-18 07:33:18
【问题描述】:

在我的 .NET MVC 应用程序中,我有一个表单。 此表单包含一个带有标签的复选框。如果这被推送,它会触发一个更新 DB 值(真/假)的控制器方法

在 chrome 中一切正常。在 IE 中,它仅在单击复选框时有效,而不是其标签。

<form class="form-horizontal" method="POST" 
 action="/Cards/UpdateCard">

//(Other labels that is not editable)

     <div class="col-xs-12 col-md-3 checkbox">
          <label onclick=" this.form.submit(); " id="xs-lighter">
                @if (paymentCard.AutomaticEmailEnabled)
                {
                    <input class="" type="checkbox" name="SelectedSources" checked="checked" onclick=" this.form.submit(); ">
                }
                else
                {
                    <input class="" type="checkbox" name="SelectedSources"  onclick=" this.form.submit(); ">
                }
                Automatic send mail
           </label>
     </div>
</form>

如何更改此设置以同时在 Chrome 和 IE 中运行?

【问题讨论】:

  • 标签有for属性吗? w3schools.com/tags/att_label_for.asp
  • 谢谢,这改变了一些事情。但是有一个复选框列表。因此,当我单击带有此代码的标签时,列表中的所有复选框都会更改。

标签: javascript c# asp.net-mvc


【解决方案1】:

用 jquery 试试这个

$('#xs-lighter').click(function() {
 $("#form1").submit();
});

<form class="form-horizontal" method="POST" 
 action="/MyCards/UpdatePaymentcard" id="form1">

//(Other labels that is not editable)

     <div class="col-xs-12 col-md-3 checkbox">
          <label id="xs-lighter">
                @if (paymentCard.AutomaticEmailEnabled)
                {
                    <input class="" type="checkbox" name="SelectedSources" checked="checked" onclick=" this.form.submit(); ">
                }
                else
                {
                    <input class="" type="checkbox" name="SelectedSources"  onclick=" this.form.submit(); ">
                }
                Automatic send mail
           </label>
     </div>
</form>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 2013-03-23
    • 2011-11-26
    相关资源
    最近更新 更多