gpt4 book ai didi

javascript - Textarea 必需属性在 JavaScript 中不起作用

转载 作者:行者123 更新时间:2023-12-03 06:55:28 25 4
gpt4 key购买 nike

我正在使用 Bootstrap 模态对话框让我的客户向我提出他们的意见,并且我想根据需要制作消息的 Textarea,但它不起作用,可以吗?看看并指出错误在哪里:

HTML 文件:

<ul class="nav navbar-nav">
<li><button type="button" class="btn btn-link" id="suggestion">Please let us know if you have any suggestions to
improve our service to you.</button>
</li>
</ul>

Javascript 文件:

<script>

$('#suggestion').click(function () {


BootstrapDialog.show({
title: 'Suggestion Box',
message: $('<textarea rows="10" class="form-control" id="suggested_message" placeholder="Please make your suggestions" maxlength="10" required></textarea>'),
buttons: [{
label: 'Submit',
cssClass: 'btn-primary',
hotkey: 13, // Enter.
action: function(dialogRef) {
$.ajax({
type : "POST",
data : { 'message': $('#suggested-message').val()},
url : "{{ path('service_tool_suggest') }}",
success :
BootstrapDialog.alert('Your message has been received, it will be considered as soon as possible')
})

dialogRef.close()
}
}]
});
})
</script>

最佳答案

在 BootStrapDialog 回调中,您可以测试文本区域是否为空

https://jsfiddle.net/9n7Ld0nk/

        //test value of text-area (TODO blank spaces, etc)
if (suggestedMessageTextArea.value.length === 0) {
BootstrapDialog.alert('empty area');
} else {
$.ajax({...});
}

关于javascript - Textarea 必需属性在 JavaScript 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37296599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com