HTML中表单能嵌套吗,html5 – Web组件是否允许嵌套HTML表单?

这对我来说似乎是一个非常有效的问题.

出于好奇,我快速做了一个fiddle(下面提供)测试嵌套表单的用例,其中一个在shadow root中.

var template = document.querySelector('template');

var clone = document.importNode(template.content,true);

var root = document.querySelector('#host').createShadowRoot();

root.appendChild(clone);

document.querySelector('button').onclick = function(e) {

var formValues = $('#docForm').serialize();

alert(formValues);

$('#result').text(formValues);

return false;

}

document.querySelector('#host').shadowRoot.querySelector('button').onclick = function(e) {

var form = document.querySelector('#host').shadowRoot.querySelector('#shadowForm');

alert($(form).serialize());

$('#result').text($(form).serialize());

return false;

}

Submit shadow form

A

B

C

Submit document Form

IMO它按预期工作,当你提交一个在轻DOM中的表单,其中包含一个元素的shadowRoot中的表单,它们都呈现完美.

just how isolated the internals of a WebComponent are to the ancestor

elements that contain them

Shadow Root是与特定元素相关联的不同节点,它不能使用常规DOM操作API访问,因此不会干扰轻型DOM标记,在这种情况下是form-in-form规则.

I could imagine that if nesting of forms is not possible using

WebComponents … if a consumer isn’t aware of the internals of the component.

因此,要回答这个问题,用户可以在页面上放置他们想要的任何html,如果该组件使用shadow DOM进行封装,则其渲染行为不会受到他们使用的组件的影响.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值