问题描述
在 Howard E 的帮助下,我能够将下拉字段中的输入作为占位符显示到另一个字段中。您可以找到该问题 here。
现在我想以相同的形式将任何类型的输入字段输入到段落中的句子中。
我试过这段代码,但不幸的是没有用。
<p>Is [recent-years] is gonna be a good year?</p>
[recent-years]
是 cf7 输入字段的名称。在这种情况下是一个下拉字段。但也很想知道文本字段和单选/选择输入字段。
我想可以使用 jQuery,但我的知识不是那么好。
希望有人可以提供帮助。谢谢!
解决方法
你可以在表格上试试这个
<p>Is <span id="recent-years"></span> is gonna be a good year?</p>
对于 jQuery 使用这个:
jQuery(document).ready(function( $ ){
$('select[name="recent-years"]').on('change',function(){
updateParagraph();
});
updateParagraph();
function updateParagraph(){
// Assign variable $placeholder to the chosen value
let $placeholder = $('select[name="recent-years"]').val();
// replace 'your-field-name' with the cf7 field name
$('input[name="your-field-name"]').attr('placeholder',$placeholder);
//New code to also add to the form html
$('#recent-years').html($placeholder);
}
});
已测试工作,见下文