我有一个表单的唯一标识符字段,用户需要输入,当传递这个值时,它需要出现在不同的字段id中。举个例子。用户在其中输入唯一代码的字段称为“唯一”,副本需要在“消息”中,我该如何实现?
<div data-role="fieldcontain">
<label for="pins" id="pinLabel"><span style="color:#f22300">*</span> Unique Code:</label>
<input data-mini="true" name="pins_r" id="pins" placeholder="9 alphanumeric characters"/>
</div>
<input type="hidden" id="msg" name="msg" value=pins>
谢谢
发布于 2012-03-19 05:54:53
对于JavaScript,有两种方法可以做到这一点。
方法1)
在唯一字段上有一个onchange事件,这样每当值发生更改时,都可以在一个名为message的隐藏字段中更改它。
<input type="text" id="unique" name="unique" onchange="setMessage(this);">
<input type="hidden" id="message" name="message">
function setMessage(field) {
document.getElementById('message').value = field.value;
}
方法2)
使用ajax发布表单,这样您就可以自己构建字段了。
即。post message= document.getElementById('unique').value
如果您使用JQuery或其他JS助手框架,上述两个方面都会得到极大的改进。
发布于 2012-03-19 06:05:07
如果希望同时在标签中设置值,请输入该值。
你可以做一些这样的事情。
$(document).ready(function() {
$('#pins').keypress(function() {
setTextValueForPins(this);
});
});
function setTextValueForPins(textPin)
{
$('#pinLabel').text($('#textPin').val());
}
如果希望在用户输入值之后设置该值,则可以使用change事件。
PS:没有测试代码,如果你遇到任何问题,请让我知道。
https://stackoverflow.com/questions/9765588
复制