I am trying to pass a js function to a button using Pug.(我正在尝试使用Pug将js函数传递给按钮。)
I saw this question here, but it does not seem to cover how to format the js function.(我在这里看到了这个问题 ,但似乎并未涵盖如何格式化js函数。)
I could not find documentation explaining how to do this, but perhaps it is on pug.org and I just do not understand it.(我找不到说明如何执行此操作的文档,但是也许它在pug.org上,我只是不理解。)
Any links to documentation/ an explanation would be great.(任何到文档的链接/说明都很好。)
Anyway, I had the following:(无论如何,我有以下几点:)
extends layout
block content
h1=title
-var itemNumber= 1;
-function add_fields() {
-itemNumber++;
-var objTo = document.getElementById('incomeItems');
-var divtest = document.createElement("div");
-divtest.innerHTML = '<div class="label">Item ' + itemNumber +':</div><div class="content"><span>Item Name: <input type="text" style="width:150px;" name="itemName[]" value="" /><small></small></span><span> Income Amount: <input type="number" style="width:60px;" namae="itemAmount[]" value="" /><small></small></span></div>';
-objTo.appendChild(divtest);
-}
form(method='POST' action='')
div.form-group
label(for='name') Budget Name:
input#budget_name.form-control(type='text', placeholder='Such as: New Building Budget' name='name' required='true' value=(undefined===budget ? '' : budget.name) )
div.form-group#incomeItems
label(for='income') Income:
input#income.form-control(type='number', name='income' required='true' value=(undefined===budget ? '' : budget.income) )
button.btn.btn-primary(type='button' onclick='add_fields()') Add Income Item
div.form-group
label(for='expenses') Expenses:
input#expenses.form-control(type='number', name='expenses' required='true' value=(undefined===budget ? '' : budget.expenses) )
button.btn.btn-primary(type='submit') Submit
if errors
ul
for error in errors
li!= error.msg
I was only able to get it to work using script.
(我只能使用script.
来使其工作script.
)
(which maybe is fine but I thought perhaps was not the best way to approach this?)((这也许很好,但我认为也许不是解决此问题的最佳方法?))
extends layout
block content
h1=title
script.
var itemNumber= 1;
function add_fields() {
itemNumber++;
var objTo = document.getElementById('incomeItems');
var divtest = document.createElement("div");
divtest.innerHTML = '<div class="label">Item ' + itemNumber +':</div><div class="content"><span>Item Name: <input type="text" style="width:150px;" name="itemName[]" value="" /><small></small></span><span> Income Amount: <input type="number" style="width:60px;" namae="itemAmount[]" value="" /><small></small></span></div>';
objTo.appendChild(divtest);
}
form(method='POST' action='')
div.form-group
label(for='name') Budget Name:
input#budget_name.form-control(type='text', placeholder='Such as: New Building Budget' name='name' required='true' value=(undefined===budget ? '' : budget.name) )
div.form-group#incomeItems
label(for='income') Income:
input#income.form-control(type='number', name='income' required='true' value=(undefined===budget ? '' : budget.income) )
button.btn.btn-primary(type='button' onclick='add_fields()') Add Income Item
div.form-group
label(for='expenses') Expenses:
input#expenses.form-control(type='number', name='expenses' required='true' value=(undefined===budget ? '' : budget.expenses) )
button.btn.btn-primary(type='submit') Submit
if errors
ul
for error in errors
li!= error.msg
I could not find the script.
(我找不到script.
)
at https://pugjs.org/language/code.html , so I am not sure how I was supposed to go about this.(在https://pugjs.org/language/code.html ,所以我不确定应该怎么做。)
ask by mso4491 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…