Хорошо, чтобы начать, когда вы это сделаете:
print(jiskya(2, 3))
Вы получаете что-то в значительной степени эквивалентное этому:
print(print(2))
Итак, что происходит? print(2)
распечатывает 2 и возвращает None
, который печатается внешним вызовом.
def hello():
return 2
Если вы это сделаете:
print(hello())
Вы получаете 2, потому что, если вы распечатываете функцию, получите значение return
. (Значение return
обозначается символом return someVariable
.
Теперь, хотя print
не имеет круглых скобок, подобных большинству функций, это функция, немного отличающаяся в этом отношении. print return? Nothing. Поэтому, когда вы print print someVariable
, вы получите None
как вторую часть, потому что возвращаемое значение печати - None
.
Так, как утверждают другие:
def jiskya(x, y):
if x > y:
print(y)
else:
print(x)
Необходимо переписать:
def jiskya(x, y):
if x > y:
return y
else:
return x
Посмотрите на jQuery Toggle
HTML:
<div id='content'>Hello World</div>
<input type='button' id='hideshow' value='hide/show'>
jQuery:
jQuery(document).ready(function(){
jQuery('#hideshow').live('click', function(event) {
jQuery('#content').toggle('show');
});
});
Для версий jQuery 1.7 и более новое использование
jQuery(document).ready(function(){
jQuery('#hideshow').on('click', function(event) {
jQuery('#content').toggle('show');
});
});
Вы можете использовать следующее:
mydiv.style.display === 'block' = (mydiv.style.display === 'block' ? 'none' : 'block');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#hideshow').click(function(){
$('#content').toggle('show');
});
});
</script>
И html
<div id='content'>Hello World</div>
<input type='button' id='hideshow' value='hide/show'>
Чистый JavaScript:
var button = document.getElementById('button'); // Assumes element with id='button'
button.onclick = function() {
var div = document.getElementById('newpost');
if (div.style.display !== 'none') {
div.style.display = 'none';
}
else {
div.style.display = 'block';
}
};
jQuery:
$("#button").click(function() {
// assumes element with id='button'
$("#newpost").toggle();
});
Вот простой способ Javascript:
<script>
var toggle = function() {
var mydiv = document.getElementById('newpost');
if (mydiv.style.display === 'block' || mydiv.style.display === '')
mydiv.style.display = 'none';
else
mydiv.style.display = 'block'
}
</script>
<div id="newpost">asdf</div>
<input type="button" value="btn" onclick="toggle();">
Вот как я скрываю и показываю контент с помощью класса. изменение класса на ничего изменит отображение на блок, изменение класса на «a» покажет отображение как none.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color:#777777;
}
block1{
display:block; background-color:black; color:white; padding:20px; margin:20px;
}
block1.a{
display:none; background-color:black; color:white; padding:20px; margin:20px;
}
</style>
</head>
<body>
<button onclick="document.getElementById('ID').setAttribute('class', '');">Open</button>
<button onclick="document.getElementById('ID').setAttribute('class', 'a');">Close</button>
<block1 id="ID" class="a">
<p>Testing</p>
</block1>
</body>
</html>