我正在尝试制作一个 Javascript 脚本,要求用户输入有关一本书的详细信息,然后为它生成一个 MLA 风格的引文。以下是我的 HTML 代码。
<input type="text" value="Author last name" id="lname"/><br />
<input type="text" value="Title of book" id="booktitle"/><br />
<input type="text" value="City of Publication" id="pubcity"/><br />
<input type="text" value="Publisher" id="pub"/><br />
<input type="text" value="Year of Publication" id="pubyear"/><br />
<input type="text" value="Number of footnote" id="footnote"/>
<br />('Number of footnote' only applicable if you plan to generate a footnote citation.)<br />
<button type="button" onclick="generateBookFootnote()">Generate Footnote</button>
<button type="button" onclick="generateBookEndnote()">Generate Endnote</button>
</form>
<p id="cite"></p>
我的Javascript如下。
function generateBookFootnote()
{
//I was just trying to do this, which I got from another StackOverflow question. Result below.
var fname = document.getElementById('fname');
var lname = document.getElementById('lname');
var booktitle = document.getElementById('bookititle');
var pubcity = document.getElementById('pubcity');
var pubyear = document.getElementById('pubyear');
var pub = document.getElementById('pub');
var footnote = document.getElementById('footnote');
document.getElementById("cite").innerHTML=document.getElementById( fname );
};
所以我尝试了互联网上的许多方法,试图让它打印出文本框的内容fname
。var fname = document.getElementById('fname');
打印出[object HTMLInputElement]
的不是实际值。运行该document.getElementById("cite").innerHTML=document.getElementById( fname );
功能时,不打印任何内容。到目前为止,这是我在 Internet 上找到的仅有的两个解决方案。