Javascript 按钮单击不工作时需要验证JavsScript
我正在尝试添加验证,因此当单击“上载”按钮时,如果文本框为空,则不要推进进度栏并添加验证消息。但是,如果文本框中有一个值,则在该栏中前进Javascript 按钮单击不工作时需要验证JavsScript,javascript,jquery,css,html,validation,Javascript,Jquery,Css,Html,Validation,我正在尝试添加验证,因此当单击“上载”按钮时,如果文本框为空,则不要推进进度栏并添加验证消息。但是,如果文本框中有一个值,则在该栏中前进 function makeProgress(){ if ($('#textbox').val() == '') { alert("Please upload a file."); } else { $("#pbarmain").show();
function makeProgress(){
if ($('#textbox').val() == '') {
alert("Please upload a file.");
}
else
{
$("#pbarmain").show();
$("#pbar").show();
if(i < 100){
i = i + 4;
$(".progress-bar").css("width", i + "%").text(i + " %");
setTimeout("makeProgress()", 100);
}
}
<input type="text" id = "textbox" class="form-control" readonly>
<button type="button" onClick="makeProgress()" class="btn btn-default" >Upload</button>
<button type="button" id ="reset" class="btn btn-default" data-dismiss="modal">Close</button>
函数makeProgress(){
如果($('#文本框').val()=''){
警告(“请上传文件”);
}
其他的
{
$(“#pbarmain”).show();
$(“#pbar”).show();
如果(i<100){
i=i+4;
$(“.progress bar”).css(“宽度”,i+“%”)。文本(i+“%”);
setTimeout(“makeProgress()”,100);
}
}
上传
接近
上传
接近
函数makeProgress(){
如果($('#文本框').val()=''){
警告(“请上传文件”);
}
其他的
{
$(“#pbarmain”).show();
$(“#pbar”).show();
如果(i<100){
i=i+4;
$(“.progress bar”).css(“宽度”,i+“%”)。文本(i+“%”);
setTimeout(“makeProgress()”,100);
}
}
}
如果您不希望进度条继续运行,我认为您需要为此返回false。这将停止执行[else]语句中给出的内容
if ($('#textbox').val() === '') {
alert('Your alert message');
return false;
}
希望这对您有所帮助将JavaScript代码放入
请记住,i
没有定义。
与progressbar元素和其他条相同(pbarmain
和pbar
)
还要确保在代码中包含Jquery
<script type="text/javascript">
function makeProgress() {
if ($('#textbox').val() == '') {
alert("Please upload a file.");
} else {
$("#pbarmain").show();
$("#pbar").show();
if (i < 100) {
i = i + 4;
$(".progress-bar").css("width", i + "%").text(i + " %");
setTimeout("makeProgress()", 100);
}
}
}
</script>
<input type="text" id="textbox" class="form-control">
<button type="button" onClick="makeProgress()" class="btn btn-default">Upload</button>
<button type="button" id="reset" class="btn btn-default" data-dismiss="modal">Close</button>
函数makeProgress(){
如果($('#文本框').val()=''){
警告(“请上传文件”);
}否则{
$(“#pbarmain”).show();
$(“#pbar”).show();
如果(i<100){
i=i+4;
$(“.progress bar”).css(“宽度”,i+“%”)。文本(i+“%”);
setTimeout(“makeProgress()”,100);
}
}
}
上传
接近
接近
上传
浏览
var i=0;
var makeProgress=函数(){
console.log(“在此登录”);
如果($('#文本框').val()=''){
警告(“请上传文件”);
}
其他的
{
$(“#pbarmain”).show();
$(“#pbar”).show();
如果(i<100){
i=i+4;
$(“.progress bar”).css(“宽度”,i+“%”)。文本(i+“%”);
setTimeout(“makeProgress()”,100);
}
}
}
在函数的末尾添加一个}
,否则括号就不匹配了。这是怎么回事?Angelos-这似乎不起作用。它仍然在进度条上前进,并且没有出现警报。请做一个提琴我在哪里声明?巴诺问题的进展在哪里。很高兴我们能帮忙。请不要忘记在这里投票接受答案。这对我们大家都有帮助。嗨,我该怎么做?我是新来的点击某个答题贴左侧的大/小箭头。参考:stackoverflow.com/help/privileges/vote-up。谢谢
<script type="text/javascript">
function makeProgress() {
if ($('#textbox').val() == '') {
alert("Please upload a file.");
} else {
$("#pbarmain").show();
$("#pbar").show();
if (i < 100) {
i = i + 4;
$(".progress-bar").css("width", i + "%").text(i + " %");
setTimeout("makeProgress()", 100);
}
}
}
</script>
<input type="text" id="textbox" class="form-control">
<button type="button" onClick="makeProgress()" class="btn btn-default">Upload</button>
<button type="button" id="reset" class="btn btn-default" data-dismiss="modal">Close</button>