我想在html中连接两个文本字段,并在其他测试字段中显示结果 [英] I want to concatenate two text fields in html and display the result in other test field

查看:75
本文介绍了我想在html中连接两个文本字段,并在其他测试字段中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码

First name : <input type="text" name="txtFirstName" /> <br><br>
Last name : <input type="text" name="txtLastName" /> <br><br>
Full name : <input type="text" name="txtFullName"  > <br><br>

如果我在名字文本框中输入abc,在名字文本框中输入def,则结果应在全名文本框中显示为abcdef.该怎么做?

if i give abc in first name text box and def in last name text box the result should be displayed as abcdef in full name text box. How to do this?

推荐答案

使用形式为oninput的属性的少量内联JavaScript实际上非常简单.

It's actually quite simple with a tiny bit of inline JavaScript using the form oninput attribute.

<form oninput="txtFullName.value = txtFirstName.value +' '+ txtLastName.value">
  First name : <input type="text" name="txtFirstName" /> <br><br>
  Last name : <input type="text" name="txtLastName" /> <br><br>
  Full name : <input type="text" name="txtFullName"  > <br><br>
</form>

http://jsfiddle.net/RXTV7/1/

我还建议使用HTML5 <output>元素代替第三个输入.要了解更多信息,请从这里开始: http://html5doctor.com/the-output-element/

I'd also suggest using HTML5 <output> element instead of third input. To learn more start here: http://html5doctor.com/the-output-element/

这篇关于我想在html中连接两个文本字段,并在其他测试字段中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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