gpt4 book ai didi

javascript - 模态窗口而不是警报

转载 作者:行者123 更新时间:2023-11-30 05:56:36 25 4
gpt4 key购买 nike

我需要修改此脚本,以便在允许的字符数结束时,用户可以看到模态警告窗口,而不是提醒用户,该窗口在 N 秒后消失。在这种情况下,光标应该卡住在原地并且无法进一步键入。预先感谢您的建议。

这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Textbox</title>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#contentbox").keyup(function()
{
var box=$(this).val();
var main = box.length *100;
var value= (main / 145);
var count= 145 - box.length;

if(box.length <= 145)
{
$('#count').html(count);
$('#bar').animate(
{
"width": value+'%',
}, 1);
}
else
{
alert(' Stop! ');
}
return false;
});

});
</script>
<style>
#barbox
{
float:right!;
height:14px;
background-color:#FFFFFF;
width:100px;
border:solid 2px #000;
margin-right:3px;
margin-bottom:10px;
overflow: inherit;
}
#bar
{
background-color:#ff0000;
width:0px;
height:14px;
}
#count
{
float:right; margin-right:8px;
font-family:'Georgia', Times New Roman, Times, serif;
font-size:16px;
font-weight:bold;
color:#333;
}
#contentbox
{
width:450px; height:50px;
border:solid 2px #006699;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
}
</style>
</head>
<body>
<div>
<div id="count">145</div>
<div id="barbox"><div id="bar"></div></div>
</div>
<textarea id="contentbox"></textarea>
</body>
</html>

最佳答案

您可以使用 jQuery 库来创建模式对话框: http://jqueryui.com/demos/dialog/#modal

这是一个使用您的代码的示例:http://jsfiddle.net/ZZsTS/

JS

$( "#dialog-modal" ).dialog({
height: 140,
modal: true,
autoOpen: false,
//set a timeout of 3 secs to close it again, when opened
open: function(event, ui) {
setTimeout("$('#dialog-modal').dialog('close')", 3000);
},
//when closing, make the textarea readonly
close : function(){
$('textarea').attr('readonly', 'readonly');
}
});

打开对话框

$('#dialog-modal').dialog('open');

HTML

<textarea></textarea>

<div id="dialog-modal" title="Basic modal dialog">
<p>Stop !</p>
</div>

关于javascript - 模态窗口而不是警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478441/

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