布尔玛是否有任何简单的表单验证方法?我认为简单的HTML5输入验证(input step="any" type="number"
)可能有效,但布尔玛忽略了它。我看到了一些用于表单验证的JS库,这些库与Bulma兼容,但是没有更简单的方法吗?也许通过oninvalid()
事件添加了is-danger
样式并在没有错误的情况下又变回原来的样式?
<form method="post">
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="price">
Price
</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="price" min="1" name="price" placeholder="Price" step="any" type="number"/>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label" for="quantity">
Quantity
</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="input" id="quantity" name="quantity" placeholder="Quantity" type="number"/>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label">
<!-- Left empty for spacing -->
</div>
<div class="field-body">
<div class="field">
<div class="control">
<input class="button is-success is-outlined" name="submitSave" type="submit" value="Save"/>
</div>
</div>
</div>
</div>
</form>
答案 0 :(得分:0)
没有JavaScript,就无法更改CSS .class选择器。
在您的情况下,可以通过以下简单代码使用伪类invalid获得所需的结果:
cubed = []
for number in numbers_to_cube:
cubed.append(number**3)
print(cubed) # Prints [1331, 1728, 2197, 2744, 3375]