Php 一旦javascript计时器结束,如何禁用提交按钮?
我有一个javascript计时器,从某个日期开始运行到零,我需要禁用html/php页面上的提交按钮,这是我的表单代码。我试过很多方法,但似乎都不管用Php 一旦javascript计时器结束,如何禁用提交按钮?,php,javascript,form-submit,Php,Javascript,Form Submit,我有一个javascript计时器,从某个日期开始运行到零,我需要禁用html/php页面上的提交按钮,这是我的表单代码。我试过很多方法,但似乎都不管用 <form id="MakeBid" action="MakeBid.php" method="POST"> <input type="hidden" name="propertyID" value ="1"/> <div>Bid Now <input type="text" name="pri
<form id="MakeBid" action="MakeBid.php" method="POST">
<input type="hidden" name="propertyID" value ="1"/>
<div>Bid Now <input type="text" name="pricesoldfor"/></div>
<input id = "submit" type="submit" value="Submit" />
</form>
现在出价
这是我的javascript代码
function calcage(secs, num1, num2) {
s = ((Math.floor(secs / num1)) % num2).toString();
if (LeadingZero && s.length < 2) s = "0" + s;
return "<b>" + s + "</b>";
}
function CountBack(secs) {
if (secs < 0) {
document.getElementById("cntdwn").innerHTML = FinishMessage;
return;
}
DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs, 86400, 100000));
DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs, 3600, 24));
DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs, 60, 60));
DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs, 1, 60));
document.getElementById("cntdwn").innerHTML = DisplayStr;
if (CountActive) setTimeout("CountBack(" + (secs + CountStepper) + ")", SetTimeOutPeriod);
}
function putspan(backcolor, forecolor) {
document.write("<span id='cntdwn' style='background-color:" + backcolor + "; color:" + forecolor + "'></span>");
}
if (typeof(BackColor) == "undefined") BackColor = "white";
if (typeof(ForeColor) == "undefined") ForeColor = "black";
if (typeof(TargetDate) == "undefined") TargetDate = "12/31/2020 5:00 AM";
if (typeof(DisplayFormat) == "undefined") DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
if (typeof(CountActive) == "undefined") CountActive = true;
if (typeof(FinishMessage) == "undefined") FinishMessage = "";
if (typeof(CountStepper) != "number") CountStepper = -1;
if (typeof(LeadingZero) == "undefined") LeadingZero = true;
CountStepper = Math.ceil(CountStepper);
if (CountStepper == 0) CountActive = false;
var SetTimeOutPeriod = (Math.abs(CountStepper) - 1) * 1000 + 990;
putspan(BackColor, ForeColor);
var dthen = new Date(TargetDate);
var dnow = new Date();
if (CountStepper > 0) ddiff = new Date(dnow - dthen);
else ddiff = new Date(dthen - dnow);
gsecs = Math.floor(ddiff.valueOf() / 1000);
CountBack(gsecs);
函数计算(秒,num1,num2){
s=((数学层(秒/num1))%num2.toString();
如果(导零和导秒长度<2)s=“0”+s;
返回“+s+”;
}
函数倒计时(秒){
如果(秒<0){
document.getElementById(“cntdwn”).innerHTML=FinishMessage;
返回;
}
DisplayStr=DisplayFormat.replace(/%%D%%/g,calage(secs,86400100000));
DisplayStr=DisplayStr.replace(/%%H%%/g,calage(secs,3600,24));
DisplayStr=DisplayStr.replace(/%%M%%/g,calage(secs,60,60));
DisplayStr=DisplayStr.replace(/%%S%%/g,calage(secs,1,60));
document.getElementById(“cntdwn”).innerHTML=DisplayStr;
如果(CountActive)setTimeout(“倒计时”(+(秒+CountStepper)+)”,则SetTimeOutPeriod;
}
功能putspan(背景色、前景色){
文件。填写(“”);
}
如果(typeof(BackColor)=“未定义”),BackColor=“白色”;
如果(typeof(ForeColor)=“未定义”)ForeColor=“黑色”;
如果(typeof(TargetDate)=“未定义”)TargetDate=“12/31/2020 5:00 AM”;
如果(typeof(DisplayFormat)=“未定义”)DisplayFormat=“%%D%%天、%%H%%小时、%%M%%分钟、%%S%%秒。”;
如果(typeof(CountActive)=“未定义”),CountActive=true;
如果(typeof(FinishMessage)=“未定义”)FinishMessage=“”;
如果(typeof(CountStepper)!=“number”)CountStepper=-1;
如果(typeof(LeadingZero)=“未定义”),LeadingZero=true;
CountStepper=Math.ceil(CountStepper);
如果(CountStepper==0)CountActive=false;
var SetTimeOutPeriod=(Math.abs(CountStepper)-1)*1000+990;
putspan(背景色、前景色);
var dthen=新日期(TargetDate);
var dnow=新日期();
如果(CountStepper>0)ddiff=新日期(dnow-dthen);
else ddiff=新日期(dthen-dnow);
gsecs=数学地板(ddiff.valueOf()/1000);
倒计时(gsecs);
当js计时器用完时调用此代码
document.getElementById("xx").disabled = true;
用您的提交按钮id填写xx。最简单的方法是隐藏提交按钮:
document.getElementById('submit').style.display='none';
我想你的计时器在下面的情况下停止了,所以把代码放在这里禁用你的按钮。将提交按钮的id更改为btnsubmit
if (CountStepper == 0)
{
CountActive = false;
document.getElementById("btnsubmit").disabled = true;
}
您是否尝试了
document.getElementById('submit')。disabled=true代码>
修改函数倒计时
,如下所示:
function CountBack(secs) {
if (secs < 0) {
document.getElementById("cntdwn").innerHTML = FinishMessage;
document.getElementById( 'submit' ).disabled = true;
return;
}
函数倒计时(秒){
如果(秒<0){
document.getElementById(“cntdwn”).innerHTML=FinishMessage;
document.getElementById('submit').disabled=true;
返回;
}
我试着把它放进去,我应该把它放在哪里才能工作?我不能正确地使用它。我把它放在这个函数CountBack(secs)中,并把我的代码放在你写的if语句的某个地方。我调用了那个函数,但它似乎仍然不起作用。这是我插入代码函数CountBack(secs){if(secs<0){document.getElementById(“cntdwn”).innerHTML=FinishMessage;document.getElementById('submit').disabled=true;return;这与Java有什么关系吗?有什么关系吗?是否删除Java标记?