我想使用.js
将输入表单导出到.html
代码预览和文件中,但是输入值无法显示为'id'元素。请帮我什么可以编辑此代码的问题?
html代码:
<div>
<input type="text" id='btn' disable='disable' value="Content">
</div>
<div id='content'></div>
<div id='main'>
<textarea id='code'></textare>
</div>
<a href="#" id="downloadLink">DOWNLOAD</a>
Js代码:(输入值)
var oBtn = document.getElementById('btn');
var oTi = document.getElementById('content');
var oCode = document.getElementById('code')
if ('oninput' in oBtn) {
oBtn.addEventListener("input", getWord, false);
} else {
oBtn.onpropertychange = getWord;
}
function getWord() {
oTi.innerHTML = oBtn.value;
oCode.innerHTML = oTi.value;
}
JS代码:(导出.html)
function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.createElement('a');
mimeType = mimeType || 'text/plain';
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
var fileName = 'tags.html';