[英]choosing checkbox echoing submit button immediately
如果我有復選框並通過選擇它(沒有任何提交按鈕)向我顯示提交按鈕,代碼是什么
<html>
<head>
<title>test</title>
<form method="post">
<?php
//what will be the code here?
?>
<input type='checkbox' name='cb'>
</form>
</html>
沒有 Javascript 根本做不到。 用 Javascript?
簡單,快速,甜蜜和平易近人
<script>
function openinput() {
document.getElementById('submit').style.visibility = "visible";
}
</script>
<form>
<input type="checkbox" onclick="openinput()" />
<input type="submit" id="submit" value="go" style="visibility: hidden" />
</form>
不是 JS 人,但像這樣簡單的東西應該可以工作(未經測試的代碼):
<script>
function showHide(obj){
if(obj.checked==true){
document.getElementById('submit_btn').style.display = 'inline';
}else{
document.getElementById('submit_btn').style.display = 'none';
}
}
</script>
<form method="post">
<input type='checkbox' name='cb' onclick="showHide(this)">
<input type="submit" id="submit_btn" value="submit" style="display:none" />
</form>
當然還有更優雅的解決方案,使用像 JQuery 這樣的框架
像這樣的東西,但這只有在您確實提交了表單但除了此檢查之外不對帖子值做任何事情時才有效。 JavaScript 將是更好的選擇。
<?php
if(isset($_POST['cb'])) {
?>
<input type="submit" value="go power rangers" />
<?php
};
?>
原始代碼:(在 jQuery v1.6 中)
$('input[type="checkbox"]').change(function() {
var $input = $(this);
if($input.prop('checked')){
alert('checked');
$('input[type="submit"]').show();
}
else
$('input[type="submit"]').hide();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.