如何获取动态表单来更新HTML中的文本? [英] How do I get a dynamic form to update Text in HTML?

查看:148
本文介绍了如何获取动态表单来更新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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆