gpt4 book ai didi

javascript - 通过 jquery 检查文本字段是否为空

转载 作者:行者123 更新时间:2023-11-30 06:51:22 24 4
gpt4 key购买 nike

我有以下代码

$('#myform').submit(function() {
return false;
});

$('#insert').click(function() {
var value = $.trim($("#msg").val());
if (value.length < 0) {
alert("לא הכנסת הודעה !");
} else {
$.post(
$('#myform').attr('action'),
$('#myform :input').serializeArray(),
function(result) {
document.getElementById('msg').value = "";
$('#result').html(result);
}
);
}
});
<form method="post" action="insertmsg.php" id="myform">
<table>
<tr>
<td width="100%">
<textarea class="form-control" placeholder="ההודעה שלך" name="msg" id="msg"></textarea>
</td>
<td>
<button id='insert' class="form-control">שלח</button>
</td>
</tr>
</table>

<p id='result'></p>
</form>

我无法检查该字段是否为空。我尝试了一些方法,但它不起作用。

有什么建议吗?

最佳答案

if ($(textarae #msg).val() == '' || $(textarae #msg).val() == null)

关于javascript - 通过 jquery 检查文本字段是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44656674/

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