我正在开发一个内部网页,以帮助自动执行某些电子邮件任务。我目前有一个表单,其中包含一些通用信息,这些表单在以下所有表单中都是相同的,还有一些其他表单具有一些自定义信息。我的问题是我无法从信息表单中获取数据以复制到页面上的其他表单。我的代码如下:
<html>
</body>
<script language="JavaScript">
function updateInput(ish){
document.getElementById("emailsubj").value = ish;
}
</script>
<body>
Info Form
<form id="info" name="info">
Email Subjects:<input name="emailsubj" value="Enter Subject Here">
</form>
<br><br>
Form 1
<form id="form1" name="form1">
Email<input name=emadd value="email@address.com">
Subject<input name="subj" onblur="updateInput(this.value)">
</form>
<br><br>
Form 2
<form id="form2" name="form2">
Email<input name=emadd value="email@address.com">
Subject<input name="subj" onblur="updateInput(this.value)">
</form>
</body>
</html>
所有非信息表单都会有一个提交按钮来执行相应的功能。我并不反对使用onchange而不是onblur,但是在我的测试中测试并没有帮助我。提前致谢!
答案 0 :(得分:0)
jQuery回答 http://codepen.io/anon/pen/aKIgc
HTML
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
</head>
<body>
Info Form
<form id="info" name="info">
Email Subjects:<input name="emailsubj" placeholder="Enter Subject Here">
</form>
Form 1
<form id="form1" name="form1">
Email<input name="emadd" placeholder="email@address.com">
Subject<input name="subj">
</form>
Form 2
<form id="form2" name="form2">
Email<input name="emadd" placeholder="email@address.com">
Subject<input name="subj">
</form>
</body>
</html>
SCRIPT
$('input[name=emailsubj]').on("keyup",function(e){
$('[name=subj]').val($(this).val())
});
没有jQuery回答 http://codepen.io/anon/pen/BzKxG
<html><body>
Info Form
<form id="info" name="info">
Email Subjects:<input name="emailsubj" value="Enter Subject Here" onblur="updateInput(this.value)">
</form>
<br/><br/>
Form 1
<form id="form1" name="form1">
Email<input name="emadd" value="email@address.com">
Subject<input name="subj">
</form>
<br/><br/>
Form 2
<form id="form2" name="form2">
Email<input name="emadd" value="email@address.com">
Subject<input name="subj">
</form>
</body></html>
JS
function updateInput(ish){
var a = document.getElementsByName("subj");
for(var i in a){
a[i].value = ish;
}
}