1

我正在开发一个内部网页,以帮助自动化一些电子邮件任务。我目前有 1 个表单,其中包含一些在以下所有表单中都相同的通用信息,以及其他几个具有一些自定义信息的表单。我的问题是我无法从信息表单中获取数据以复制到页面上的其他表单。我的代码如下:

<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,但是测试对我的测试没有任何帮助。提前致谢!

4

1 回答 1

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>

脚本

$('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;
    }
}
于 2013-03-08T20:20:53.053 回答