如何获取动态表单来更新HTML中的文本? [英] How do I get a dynamic form to update Text in HTML?
问题描述
我试图在加入HTML时添加名称:
我有一个名为Gravity
您好[名字]
其中Hello [name]位于HTML中(不在表单中)
其中[name]由输入文本替换字段,我希望它是什么?
我创建了表单,发现字段名称是:input_1
,字段的id是input_32_1
我试过这段代码:
< script>
$(document).ready(function(){
$(#input_32_1)。keyup(function(){
document.getElementById(fname)。innerHMTL = document。 getElementsByName('input_1')[0] .value;
});
});
< / script>
但它不起作用。
您能告诉我我做错了什么吗?
您的标记应该是:
您好< span id =nameFromInput>< / span>
然后脚本就是:
<$ p ($(#input_32_1).val())。$ p> $(#input_32_1)。 ;
});
这是一个jsfiddle,它的工作方式如上:
http://jsfiddle.net/cTq7K/
I have a form that is built with a wordpress plugin called Gravity forms.
I am trying to have the name when it is added be added to the HTML:
Hello [name]
Where "Hello [name]" is in the HTML (not in the form)
and where [name] is replaced by the input text field that I want it to be?
I created the form and found out that the field name is: input_1 and the id of the field is input_32_1
I tried this code:
<script>
$(document).ready(function() {
$("#input_32_1").keyup(function() {
document.getElementById("fname").innerHMTL = document.getElementsByName('input_1')[0].value;
});
});
</script>
But it is not working. Can you tell me what I did wrong?
Your markup should be:
Hello <span id="nameFromInput"></span>
And script would then be:
$("#input_32_1").keyup(function() {
$("span#nameFromInput").text($("#input_32_1").val());
});
Here is a jsfiddle with it working as above: http://jsfiddle.net/cTq7K/
这篇关于如何获取动态表单来更新HTML中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!