简体   繁体   English

在HTML文件和链接的.js文件之间使用DOM传递信息。

[英]Passing information using the DOM between HTML files and linked .js files.

Can someone tell me or show me how to pass information from a HTML page to a linked .js file? 有人可以告诉我或告诉我如何将信息从HTML页面传递到链接的.js文件吗?

<head>
<script type="text/javascript" src="../javascripts/script.js"></script>
</head>

<form name="form1">
    <input type="text" name="input1" value autofocus="on">
    <button onClick= "chrome.tabs.create({url: getURL()});">Go</button>
</form>

This is part of a form I want to be completed, and the input value taken, combined with a pre-existing URL, and the end result opened in a new tab 这是我要填写的表单的一部分,将输入值与先前存在的URL相结合,并在新选项卡中打开了最终结果

function getURL()
{
    var site = "http://www.example.com/query?f=";
    var input = document.form1.input1.value
    var output = site + input;
    return output;
}

This is the function I'll be using, but I can't work out or don't know yet how to link the input variable to the input1 form value. 这是我将要使用的函数,但是我无法计算出或不知道如何将输入变量链接到input1表单值。 The .js file is linked, rather than inside the actual HTML file. .js文件是链接的,而不是链接在实际的HTML文件中。

Help? 救命?

Elements with their IDs or names automatically mapped to hierarchically-organised properties under document , as in document.name1.name2 , is a long-deprecated practice and doesn't occur unless your document triggers quirks mode. 具有ID或名称的元素会自动映射到document下的按层次结构组织的属性,如document.name1.name2 ,这是一种长期不建议使用的做法,除非您的文档触发怪异模式,否则不会发生。 Add an ID to the input element then use 将ID添加到输入元素,然后使用

var input = document.getElementById('input_id_goes_here').value;

instead. 代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM