本文介绍了停止提交按钮,直到在文本区域写入足够的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以基本上我想要的是提交按钮被禁用,直到在文本区域中达到特定的字数。
So basically what I want is for the submit button to be disabled until a certain word count has been reached in the text area.
我已经看了一圈并试图找到方法来做到这一点,没有运气。
I have had a look around and tried to find ways to do it, with no luck.
任何提示或帮助?
Any tips or help?
<form method="post" id="writearticle" action="submitarticle.php">
<script>
$('#writearticle').submit(function(event) {
var text = $("#content").val();
text = text.split(" ");
// check for at least 10 words
if(text.length < 10){
console.log("prevented");
// prevent submit
event.preventDefault();
return false;
}
console.log("submitted");
});
</script>
<textarea rows="30" cols="85" id="content" name="content" placeholder="Write the article here. Try to abide by the instructions and keywords provided."></textarea>
<br />
<input type="submit" name="submitarticle" value="Submit Article" class="submit" />
<br /><br /><br /><br /><br />
</form>
推荐答案
向我们显示您的代码。
1)为提交按钮设置 onclick
事件 -
2)
3)返回false
和 preventDefault )
如果没有足够的单词。
Show us your code.
1) Set onclick
event for the submit button
2) Check length in textarea
3) return false
and preventDefault()
if there is not enough words.
这篇关于停止提交按钮,直到在文本区域写入足够的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!