答案 0 :(得分:1)
这是一个片段,我认为不需要太多解释。
我创建了一个文件类型数组,并使用jquery用<select>
填充<option>
。然后,当您单击save
按钮...
var types = [
{"extension": "html", "name": "HTML"},
{"extension": "txt", "name": "Plain Text"},
{"extension": "js", "name": "Javascript"},
{"extension": "css", "name": "CSS"},
]
types.forEach(function(type) {
$opt = $("<option>").attr("value", type.extension).text(type.name)
$("#saveas").append($opt)
})
function SaveAsType()
{
console.log($("#saveas").val())
/**
* Put your code here and replace:
document.getElementById("inputFileNameToSaveAs").value + ".html";
* with
document.getElementById("inputFileNameToSaveAs").value + "." + $("#saveas").val();
*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Save as <select id="saveas">
</select><button onclick="SaveAsType()">save</button>