Javascript 将内容标记添加到模板内的输入字段
我正在尝试使用新的html5模板标签来创建一个半通用表单,它可以放置在多个用例中,而不需要使用太多javascript 这是一把小提琴,显示了我所拥有的东西 我的目标是将占位符文本中的“名称”替换为Javascript 将内容标记添加到模板内的输入字段,javascript,html,web-component,html5-template,Javascript,Html,Web Component,Html5 Template,我正在尝试使用新的html5模板标签来创建一个半通用表单,它可以放置在多个用例中,而不需要使用太多javascript 这是一把小提琴,显示了我所拥有的东西 我的目标是将占位符文本中的“名称”替换为标记中通常可以找到的内容 要理解我的观点,一个假设的例子是: <div id = "hoster"> <span class = "inputPlaceholder">Special Name</span> </div> <templat
标记中通常可以找到的内容
要理解我的观点,一个假设的例子是:
<div id = "hoster">
<span class = "inputPlaceholder">Special Name</span>
</div>
<template id = "im-a-template">
<input type="text" placeholder = <content select = ".inputPlaceholder"></content>>
</template>
特殊名称
是否有一种方法可以执行类似的操作,或者是使用javascript手动设置的唯一方法?在客户端上使用XSLT来执行此操作:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="html5.xhtml"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:output method="xml" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />
<!-- Run default templates on the xsl-stylesheet element above-->
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates/>
</xsl:template>
<!-- Run this template on the root node -->
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<div id="hoster">
<span class="inputPlaceholder">Special Name</span>
</div>
<!-- Reuse the value of the node with the inputPlaceholder class -->
<template id="im-a-template">
<input type="text" placeholder="{//node()[@class='inputPlaceholder']}"/>
</template>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
特殊名称
使用以下过程:
- 另存为
(或更改html5.xhtml