Javascript 单击按钮以消失并显示隐藏字段

Javascript 单击按钮以消失并显示隐藏字段,javascript,php,jquery,css,Javascript,Php,Jquery,Css,所以基本上,我试着制作一个按钮“回电话”,当你点击它时,它会消失并显示另外两个隐藏字段 我想改变的是页面顶部的一个小表单,它有两个字段和一个回叫按钮。试试jquery的显示/隐藏功能,比如 $("#div_to_show").show(); $("#div_to_hide").hide(); 这就是你应该如何处理你的问题: HTML JS document.getElementById(“div1”).style.display=“无” document.getElementByI

所以基本上,我试着制作一个按钮“回电话”,当你点击它时,它会消失并显示另外两个隐藏字段


我想改变的是页面顶部的一个小表单,它有两个字段和一个回叫按钮。

试试jquery的显示/隐藏功能,比如

$("#div_to_show").show(); 
$("#div_to_hide").hide(); 

这就是你应该如何处理你的问题:

HTML

JS

document.getElementById(“div1”).style.display=“无”
document.getElementById(“div2”).style.display=“内联块”

document.getElementById(“div3”).style.display=“内联块”

另一个,一行:

HTML


示例

在您的视图中

    <div style="display: none;" class="hideDiv">
<input type="hidden" name="_wpcf7" value="1101">
<input type="hidden" name="_wpcf7_version" value="4.4">
<input type="hidden" name="_wpcf7_locale" value="pt_PT">
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f1101-o1">
<input type="hidden" name="_wpnonce" value="7b5f59556f">
</div>
试试这个

html代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
</script>   
<input type="text" name="text-574" value="" size="40" class="txt" placeholder="Name">
<input type="text" name="text-574" value="" size="40" class="txt" placeholder="Telephone">
        <button type="button" id="callback" >
Call Back
</button>
jQuery( document ).ready(function() {

 jQuery(".txt").hide();
    jQuery("#callback").click(function(){
    jQuery(".txt").show();
    jQuery("#callback").hide();

    });
});

您可以查看

尚未尝试任何操作,只是完成了表单。我对网页设计很陌生,仍在学习诀窍。这正是我想要的。但是我忘了提到,我正在使用联系人表单7,所以我需要调用我创建的表单,而不是那些字段,因为aldready在其中包含这些字段php@PedroBronze不确定你的评论是什么意思,上面只是一个例子,做你必须做的。@PedroBronze你当然不能按原样使用我的代码;另外,在jQuery之后添加脚本(在您的案例中,它加载在页面的末尾),将您站点上的表单切换回原始表单,我会看一看。
$(document).on('click','.send-cmb',function(e){
    e.preventDefault();
    $('.hideDiv').css('display:block');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js">
</script>   
<input type="text" name="text-574" value="" size="40" class="txt" placeholder="Name">
<input type="text" name="text-574" value="" size="40" class="txt" placeholder="Telephone">
        <button type="button" id="callback" >
Call Back
</button>
jQuery( document ).ready(function() {

 jQuery(".txt").hide();
    jQuery("#callback").click(function(){
    jQuery(".txt").show();
    jQuery("#callback").hide();

    });
});