将来自 cf7 表单的输入添加到相同表单的段落
Add input from cf7 form to paragraph in same form
在 Howard E 的帮助下,我能够将下拉字段中的输入作为占位符显示到另一个字段中。你可以找到那个问题 .
现在我想以相同的形式将任何类型的输入字段输入到段落中的句子中。
我试过这个代码,但不幸的是它没有用。
<p>Is [recent-years] is gonna be a good year?</p>
[recent-years]
是cf7输入域的名称。在本例中是一个下拉字段。但也很想知道文本字段和 radio/select 输入字段。
我想 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);
}
});
测试工作,见下文
在 Howard E 的帮助下,我能够将下拉字段中的输入作为占位符显示到另一个字段中。你可以找到那个问题
现在我想以相同的形式将任何类型的输入字段输入到段落中的句子中。
我试过这个代码,但不幸的是它没有用。
<p>Is [recent-years] is gonna be a good year?</p>
[recent-years]
是cf7输入域的名称。在本例中是一个下拉字段。但也很想知道文本字段和 radio/select 输入字段。
我想 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);
}
});
测试工作,见下文