【问题标题】:Submit Form on image click点击图片提交表格
【发布时间】:2014-12-11 20:08:58
【问题描述】:

如何在点击图片时提交表单?该表单未使用以下代码提交。有没有办法在没有 jQuery 的情况下做到这一点?

剃须刀

@using (Html.BeginForm("AssignLabels", "Home", FormMethod.Post, new { name = "frm", id = "AssignLabelsForm" }))
{
   <img src="@Url.Content("~/Images/Labels.png") />
}

jQuery

$('img').on("click", function () {
    $(this).submit();
});

控制器

[HttpPost]
public ActionResult AssignLabels()
{
    return View();
}

【问题讨论】:

  • 当您调用提交时,您希望 图像 做什么?
  • 而反对票是...?

标签: javascript jquery asp.net-mvc forms razor


【解决方案1】:

试试这个

$('img').on("click", function () {
    $('#AssignLabelsForm').submit();
});

【讨论】:

    【解决方案2】:

    使用图片按钮

    <input type="image" src="Your source of image" alt="Form submit image" />
    

    欲了解更多信息,请参阅此处https://www.w3.org/TR/html401/interact/forms.html#h-17.4.1

    【讨论】:

      【解决方案3】:

      在您的代码中,$(this) 指的是图像元素...具体指定提交表单:

      $('img').on("click", function () {
          $(form).submit();
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-21
        • 2021-01-28
        • 1970-01-01
        • 2014-10-17
        • 2011-12-07
        • 2014-05-12
        相关资源
        最近更新 更多