我有一个问题数组,当我按如下所示的格式单击“提交”按钮时,我想在其中添加HTML表单数据:
import re
s = "ↂ12½Dollars"
pN = r'0-9\u16EE-\u16F0\u2160-\u2182\u2185-\u2188\u3007\u3021-\u3029\u3038-\u303A\uA6E6-\uA6EF\U00010140-\U00010174\U00010341\U0001034A\U000103D1-\U000103D5\U00012400-\U0001246E\u00B2\u00B3\u00B9\u00BC-\u00BE\u09F4-\u09F9\u0B72-\u0B77\u0BF0-\u0BF2\u0C78-\u0C7E\u0D58-\u0D5E\u0D70-\u0D78\u0F2A-\u0F33\u1369-\u137C\u17F0-\u17F9\u19DA\u2070\u2074-\u2079\u2080-\u2089\u2150-\u215F\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2CFD\u3192-\u3195\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\uA830-\uA835\U00010107-\U00010133\U00010175-\U00010178\U0001018A\U0001018B\U000102E1-\U000102FB\U00010320-\U00010323\U00010858-\U0001085F\U00010879-\U0001087F\U000108A7-\U000108AF\U000108FB-\U000108FF\U00010916-\U0001091B\U000109BC\U000109BD\U000109C0-\U000109CF\U000109D2-\U000109FF\U00010A40-\U00010A48\U00010A7D\U00010A7E\U00010A9D-\U00010A9F\U00010AEB-\U00010AEF\U00010B58-\U00010B5F\U00010B78-\U00010B7F\U00010BA9-\U00010BAF\U00010CFA-\U00010CFF\U00010E60-\U00010E7E\U00010F1D-\U00010F26\U00010F51-\U00010F54\U00011052-\U00011065\U000111E1-\U000111F4\U0001173A\U0001173B\U000118EA-\U000118F2\U00011C5A-\U00011C6C\U00011FC0-\U00011FD4\U00016B5B-\U00016B61\U00016E80-\U00016E96\U0001D2E0-\U0001D2F3\U0001D360-\U0001D378\U0001E8C7-\U0001E8CF\U0001EC71-\U0001ECAB\U0001ECAD-\U0001ECAF\U0001ECB1-\U0001ECB4\U0001ED01-\U0001ED2D\U0001ED2F-\U0001ED3D\U0001F100-\U0001F10C'
rx = r'([{0}]) *([^{0}\W])'.format(pN)
s = re.sub(rx, r'\1 \2', s)
print(s) # => ↂ12½ Dollars
因此,我想像这样将数据添加到数组中:新问题(“问题?”,[“选项1”,“选项2”,“选项3”,“选项4”],“答案”)
答案 0 :(得分:1)
您可以这样做:
function Question (pquestion, poptions, panswer) {
this.question = pquestion;
this.options = poptions;
this.answer = panswer;
}
var questions = [
new Question("What language are we learning today?", ["Java", "C#","C++", "JavaScript"], "JavaScript"),
new Question("Which language is used for styling web pages?", ["HTML", "JQuery", "CSS", "XML"], "CSS")
];
function addQuestion() {
var question = document.getElementById("qs").value;
var option1 = document.getElementById("option1").value;
var option2 = document.getElementById("option2").value;
var option3 = document.getElementById("option3").value;
var option4 = document.getElementById("option4").value;
var answer = document.getElementById("answer").value;
var numberOfQuestions = questions.length;
questions[numberOfQuestions] = new Question(question, [option1, option2, option3, option4], answer);
alert("Thank you. We now have " + questions.length + " questions.");
}
<head>
<title>test</title>
</head>
<body>
<form>
<label>Enter question:</label>
<input type="text" id="qs" name="qs" /><br/>
<label>Option1:</label>
<input type="text" id="option1" name ="option1"/><br/>
<label>Option2:</label>
<input type="text" id="option2" name ="option2"/><br/>
<label>Option3:</label>
<input type="text" id="option3" name ="option3"/><br/>
<label>Option4:</label>
<input type="text" id="option4" name ="option4"/><br/>
<label>Enter answer</label>
<input type="text" id="answer" name="answer" /><br/>
<input type="button" name="submit" onclick="addQuestion();" value="Add quiz" />
</form>
</body>