Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单击“禁用提交”按钮_Php_Javascript - Fatal编程技术网

Php 单击“禁用提交”按钮

Php 单击“禁用提交”按钮,php,javascript,Php,Javascript,我想在单击时禁用提交按钮。我可以禁用该按钮,但我无法将post值提交给php。 <input type="submit" onclick="this.disabled = true" value="Save"/> 或参考 或者ref我在网上找到了一个替代方案。我所做的是创建一个假的禁用和隐藏按钮。当实际按钮被点击时,我将隐藏它并显示假禁用按钮 实际按钮: $onclick = " var boolconfirm = confirm('$strconfirmattempt');

我想在单击时禁用提交按钮。我可以禁用该按钮,但我无法将post值提交给php。


<input type="submit" onclick="this.disabled = true" value="Save"/>
或参考



或者ref

我在网上找到了一个替代方案。我所做的是创建一个假的禁用和隐藏按钮。当实际按钮被点击时,我将隐藏它并显示假禁用按钮

实际按钮:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
假按钮:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
echo”。
\n”;

我在网上找到了另一种选择。我所做的是创建一个假的禁用和隐藏按钮。当实际按钮被点击时,我将隐藏它并显示假禁用按钮

实际按钮:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
假按钮:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
echo”。
\n”;

如果禁用输入,则其值自然不会包含在表单数据中。提交后,您需要禁用该按钮。如果将回调绑定到
onclick
,那么它将在表单提交之前运行

你需要的是这样的东西:

jQuery:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
常规JS:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });

基本上,它没有绑定到submit按钮的
onclick
事件,而是将禁用代码绑定到文档的卸载事件(
document.onunload
),该事件在提交表单并开始离开页面时触发。

如果禁用输入,则其值自然不会包含在表单数据中。提交后,您需要禁用该按钮。如果将回调绑定到
onclick
,那么它将在表单提交之前运行

你需要的是这样的东西:

jQuery:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });
常规JS:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });

基本上,这将禁用代码绑定到文档的卸载事件(
document.onunload
),而不是绑定到提交按钮的
onclick
事件,一旦提交表单并开始离开页面,它就会被触发。

您可以使用一个隐藏字段来保存按钮的值,并从POST数据中提取该值:

<input type="hidden" id="hiddenField" value="default" />

<input type="button" id="myButton" onclick="buttonClick();">

function buttonClick()
{
    document.myForm.myButton.disabled = true;
    document.myForm.hiddenField.value = "myButtonClicked";
}

您可以使用隐藏字段来保存按钮的值,并从POST数据中提取该值:

<input type="hidden" id="hiddenField" value="default" />

<input type="button" id="myButton" onclick="buttonClick();">

function buttonClick()
{
    document.myForm.myButton.disabled = true;
    document.myForm.hiddenField.value = "myButtonClicked";
}

为什么不创建一个隐藏的禁用提交按钮和一个活动提交按钮,然后单击“显示禁用按钮”和“隐藏活动按钮”?我可以在jQuery中这样做,但是没有它我就没用了。悲哀,是吗?

为什么不创建一个隐藏的禁用提交按钮和一个活动提交按钮,然后单击“显示禁用项”和“隐藏活动项”?我可以在jQuery中这样做,但是没有它我就没用了。Sad,呃?

使用jQuery添加返回false的onClick处理程序:

<input type="submit" value="Submit" onClick="$(this).click(function() {return false;});"/>

使用jQuery添加返回false的onClick处理程序:

<input type="submit" value="Submit" onClick="$(this).click(function() {return false;});"/>

我用简单的jQuery解决了这个问题。代码在单击时删除按钮,然后附加假按钮或类似“加载…”的文本,最后发送表单

HTML:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });

与其他方法不同,如在单击并发送表单的瞬间卸载按钮更改。我认为使用重表单是更好的做法。

我用简单的jQuery解决了这个问题。代码在单击时删除按钮,然后附加假按钮或类似“加载…”的文本,最后发送表单

HTML:

$onclick = "
var boolconfirm = confirm('$strconfirmattempt');
if(boolconfirm==true){
finishattempt.style.display='none';
finishattempt2.style.display='inline';
}
return boolconfirm;";
echo "<input type=\"submit\" name=\"finishattempt\" value=\"submit\" onclick=\"$onclick\" />.
<input type=\"submit\" id=\"finishattempt2\" name=\"finishattempt2\" value=\"submit\" style=\"display:none;\" DISABLED/>\n";
$(document).ready(function() {
    $(document).unload(function() {
        $('#submit-btn').attr('disabled', 'disabled');
    });
});
document.onunload = disableSubmit;
function disableSubmit() {
    /* disable the submit button here */
}
<div class="holder"><input type='submit' value='ACCEPT' class='button'></div>
$('.button').click(function() {
        $('.button').remove();
        $('.holder').append("//fake input button or whatever you want.");
        $('.form').submit();
    });

与其他方法不同,如在单击并发送表单的瞬间卸载按钮更改。我认为使用重表单是一种更好的做法。

这里有一种使用onsubmit而不是onlick的方法:

这是在顶部:

<script type='text/javascript'>
function disableButtons()
{
  $('input[type="submit"]').attr('disabled', true);
}
</script>
然后是HTML

<form method='post' action='' onsubmit='disableButtons()'>
<input type='hidden' name='dothis' value=''>
<input type='submit' value='Submit'></form>

Onsubmit进入。 确保您的isset(PHP部分)用于提交时附带的输入,而不是提交按钮本身。您可以看到,它是PHP检查的隐藏值,而不是submit按钮,submit按钮被禁用。
通过这样做,您可以在不禁用PHP的情况下禁用提交按钮。

这里有一个使用onsubmit而不是onlick的方法:

这是在顶部:

<script type='text/javascript'>
function disableButtons()
{
  $('input[type="submit"]').attr('disabled', true);
}
</script>
然后是HTML

<form method='post' action='' onsubmit='disableButtons()'>
<input type='hidden' name='dothis' value=''>
<input type='submit' value='Submit'></form>

Onsubmit进入。 确保您的isset(PHP部分)用于提交时附带的输入,而不是提交按钮本身。您可以看到,它是PHP检查的隐藏值,而不是submit按钮,submit按钮被禁用。
通过这样做,您可以在不禁用PHP的情况下禁用submit按钮。

您可能希望展示如何禁用它。你提供的一点信息不可能帮助你。好吧,看看我之前发布的问题,我在这里似乎找不到好的可靠答案。我看到的只是人们在争论ajax和iframe。告诉我还有什么需要反馈的。嗨,丹尼尔,我会在下面展示我的代码。请随意评论。tksYou可能想展示如何禁用它。你提供的一点信息不可能帮助你。好吧,看看我之前发布的问题,我在这里似乎找不到好的可靠答案。我看到的只是人们在争论ajax和iframe。告诉我还有什么需要反馈的。嗨,丹尼尔,我会在下面展示我的代码。请随意评论。tkshi,这是可行的,但是如果我提交给php,那么POST值就会丢失。然而,我已经找到了另一种解决方案,我将在下面发布。欢迎发表评论。您好,这是可行的,但是如果我想提交给php,POST值就会丢失。然而,我已经找到了另一种解决方案,我将在下面发布。请随意评论。更好地格式化您的代码。它不应该是那种无法理解的一大块。格式化后,突出显示代码并点击
Ctrl+K
,将所有内容缩进4个空格,使其显示为预格式化的源代码。+1用于找到可行的解决方案并格式化代码。尽管将来您可能希望将代码分成更多行,这样水平滚动条就不会出现错误