PHP:单选按钮可见和隐藏按钮
PHP: Radiobutton visible and hide the button
我有一个关于PHP"单选按钮"的问题。今天,我试图编码一个单选按钮,当我选择radiobutton1时,按钮提交应该是可见的,但当我选择radiobutton2时,按钮提交应该是不可见的。
My Problem is:
当我点击radiobutton2时,我想让submit按钮不可见,然后当我点击radiobutton1时,submit按钮应该可见。我试图做的代码不使用表单的行动。我已经搜索过这个了,但是都是关于form action的
下面是我的代码:
<html>
<body>
<Input type = 'Radio' name ='con' value= 'sample'>SAmple:
<Input type = 'Radio' name ='con' value= 'other'>Others:
<input type="submit" name="submit" value="Submit">
</body>
</html>
提前感谢!
使用jQuery:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){
$('input[name=con]').change(function(){
if($('input[name=con]:checked').val() == 'sample'){
$('input[name=submit]').show();
} else {
$('input[name=submit]').hide();
}
});
});
</script>
在这里使用javascript。把你的HTML改成
<html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function show_but()
{
jQuery('#span_submit').show();
}
function hide_but()
{
jQuery('#span_submit').hide();
}
<script>
<body>
<Input type = 'Radio' name ='con' value= 'sample' onclick="show_but();">SAmple:
<Input type = 'Radio' name ='con' value= 'other' onclick="hide_but();">Others:
<span id="span_submit">
<input type="submit" name="submit" value="Submit">
</span>
</body>
</html>
这是PHP无法做到的。这是JavaScript/jQuery
检查整个工作代码-
<html>
<body>
<Input type = 'Radio' name ='con' value= 'sample'>SAmple:
<Input type = 'Radio' name ='con' value= 'other'>Others:
<input type="submit" name="submit" value="Submit" style="display:none;">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
jQuery(document).ready(function(){
//jQuery('input[name=submit]').hide();
jQuery('input[name=con]').on('change',function(){
if(jQuery(this).val() == 'sample')
jQuery('input[name=submit]').show();
else
jQuery('input[name=submit]').hide();
});
});
</script>
</body>
</html>
您也可以使用on
方法,像这样-
jQuery('input[name=con]').on('change',function(){
相关文章:
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- PHP Javascript显示/隐藏按钮不工作
- 如何隐藏按钮单击事件上的占位符
- 我的表单上的SpringWebFlow2中的每个转换都需要隐藏按钮吗
- 使用ng-hide根据条件显示/隐藏按钮
- 另一种显示和隐藏按钮的方式
- PHP If Else-隐藏按钮
- 如何显示/隐藏按钮
- jQuery 隐藏按钮,如果它们不包含文本
- 如何检测是否在主页上隐藏按钮
- 单击时隐藏按钮
- 在可丢弃的::javascript上显示隐藏按钮
- 想要使用onclick显示隐藏按钮
- 使用jQuery在ruby中显示/隐藏按钮
- 如果未输入URL,则隐藏按钮
- 当按下第二个按钮时如何隐藏按钮,以及当我点击页面的空白区域时如何使其出现
- 如何使用onmouseover和onmouseout在鼠标经过按钮时隐藏和取消隐藏按钮
- 使用运行时创建的链接来触发ASP.Net中隐藏按钮的单击处理程序
- 如何在ajax响应中隐藏按钮
- 切换时隐藏按钮