Javascript 单击时使提交按钮消失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14279686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 16:15:17  来源:igfitidea点击:

make submit button disappear when clicked

javascripthtml

提问by user1559811

I wanted to know if there was a way I could adapt this code so that when the submit button was clicked, it would disappear, but the input box would remain.

我想知道是否有一种方法可以修改此代码,以便在单击提交按钮时它会消失,但输入框会保留。

<script type="text/javascript">

 var Text = 'hello';

    function setInput(button) {
       var buttonVal = button.name,
       textbox = document.getElementById('input_' + buttonVal);
       textbox.value = Text ;
    }
</script>

<html>
      <input class='input' id="input_a1" name="a1" value="<?php {echo $a1;} ?>"> 
      <input type='submit' name='a1' value='x' onclick='setInput(this); return false;'>
</html>

回答by xlecoustillier

Simply add :

只需添加:

   button.style.visibility = "hidden";

at the end of your SetInputfunction.

在你的SetInput函数结束时。

回答by saikiran

<button onclick="style.display = 'none'">Click Me</button>

回答by freefaller

If you want it to disappear use...

如果您希望它消失,请使用...

button.style.visibility = "hidden";

However, that will leave the space the button was taking (but it will be blank).

但是,这会留下按钮占用的空间(但它将是空白的)。

If you want the space to disappear as well, use this instead of the visibility...

如果您希望空间也消失,请使用它而不是visibility...

button.style.display = "none";

回答by Adriano Silva

<script type="text/javascript">

 var Text = 'hello';

    function setInput(button) {
       var buttonVal = button.name;
       button.style.display = 'none'; // insert this line
       textbox = document.getElementById('input_' + buttonVal);
       textbox.value = Text ;
    }
</script>

回答by SBI

Write a js function that will hide an element.

编写一个隐藏元素的 js 函数。

function hide() {
    var div = document.getElementyById('whatYouWantToHide');
    div.style.display = 'none';
}

You can of course pass it as an argument, which would be the nice solution.

您当然可以将其作为参数传递,这将是一个不错的解决方案。

回答by anney

HTML (no button) : input id="myButton" type="hidden" value="Click ME? "

HTML(无按钮):输入 id="myButton" type="hidden" value="点击我?"

this line will make the button visible: document.getElementById("myButton").type="button";

这一行将使按钮可见: document.getElementById("myButton").type="button";

I found it much simple

我发现它很简单

回答by qwerky

<script type="text/javascript">
function submitform()
{
    document.forms["myform"].submit();
}
</script>
<form id="myform" action="submit-form.php">
Search: <input type='text' name='query'>
<a href="javascript: submitform()">Submit</a>
</form>