w2ui 忽略了输入标签上的值。
如何让它使用该值?
它可以很好地读取选择。
<div id="form" style="width: 750px;">
<div class="w2ui-page page-0">
<div class="w2ui-field">
<label>First Name:</label>
<div>
<input name="first_name" type="text" value="John" />
</div>
</div>
</div>
<div class="w2ui-buttons">
<button class="w2ui-btn" name="reset">Reset</button>
<button class="w2ui-btn" name="save">Save</button>
</div>
</div>
$(function() {
$('#form').w2form({
name: 'form',
url: 'server/post',
fields: [
{ field: 'first_name', type: 'text', required: true }
],
actions: {
reset: function() {
this.clear();
},
save: function() {
this.save();
}
}
});
});
如果我必须编写 JavaScript。我将如何访问这些字段?
最佳答案
您可以使用 form.record
访问输入的值。
在您的情况下 w2ui.form.record.first_name
(其中 form
是您的 w2form 的名称)。
在您的保存事件中,您可以使用 this.record
访问记录,例如:
save: function() {
console.log(this.record);
console.log(this.record.first_name);
this.save();
}
关于javascript - w2ui 忽略 html 形式的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54370706/