加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 具有angularJS的表单上的空操作属性

发布时间:2020-12-14 23:08:27 所属栏目:资源 来源:网络整理
导读:我试图在AngularJS应用程序中以正常方式提交表单但我遇到了一个问题:似乎我必须指定action属性. 根据HTML规范(http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#form-submission-algorithm): If acti

我试图在AngularJS应用程序中以正常方式提交表单但我遇到了一个问题:似乎我必须指定action属性.

根据HTML规范(http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#form-submission-algorithm):

If action is the empty string,let action be the document’s address of
the form document.

但是,如果未填充action属性,AngularJS将拒绝提交表单.
我找到的解决方法是使用action =“#”,但这不是一个可接受的解决方案,因为我可能会使用哈希,我不希望它被重写.

有没有人遇到过这个问题?

编辑:我不想对这个表单使用angular,我只是想以“旧”的方式提交它

最佳答案
在库中,您可以看到Angular在没有操作的情况下侦听表单的事件提交:https://github.com/angular/angular.js/blob/b9fa5c5a6781f4e1ec337f27d55c69db491a6555/src/ng/directive/form.js#L331

你可以评论这一行,它有效,但我反对编辑库的代码.

几行之后,你可以看到Angular正在监听事件$destroy,可以删除此事件的动作.

因此,为了避免修改Angular,您只需触发表单的此事件:

angular.element(document).ready(function(){
    angular.element(document.querySelector("#loginForm")).triggerHandler("$destroy")??; 
});

上面几行描述了这种行为的原因:

we can’t use jq events because if a form is destroyed during submission the default action is not prevented.

相关问题是:https://github.com/angular/angular.js/issues/1238

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读