jQuery "hide"函数不起作用

标签 jquery hide

我在使用 jQuery 的“隐藏”功能时遇到问题。我只是使用死链接吗?我应该使用 2.1.1 吗? “警报”功能似乎有效,但隐藏功能无效。有什么想法我还应该做什么吗?

*{
	margin: 0px;
	padding: 0px;
}

#container{
	width: 900px;
	margin: 0px auto;
	font-family: helvetica;
}

.effects{

}
	.effects button, #content{
		display: inline-block;
		/*vertical-align: top;*/
	}

	button{
		border: 2px solid grey;
		border-radius: 5px;
		padding: 5px;
		margin: 50px 0 0 0;
		position: relative;
		vertical-align: center;
		font-size: 18px;
		font-weight: bold;
	}

	#content{
		width: 700px;
	}

		#content h2, p{
			display: block;
			vertical-align: top;
			width: 700px;
		}

		h2{
			text-align: center;
			width: 700px;
		}

		p{
			width: 700px;
		}



	#border{
		border-bottom: 4px solid black;
		padding: 10px 0;
		/*margin: 10px 0;*/
	}
<!DOCTYPE>
<html>
<head>
	<title>Help me with jQuery</title>
	<link rel="stylesheet" type="text/css" href="style.css">
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){

			$('h1').click(function(){
				alert('hello');
			})
			$('#hide').click(function(){
				$('p').hide();
			})
        })
	</script>
</head>
  
<body>
	<h1>YOOO</h1>
	<div id="container">
		<div class="effects">
			<button div="hide">hide</button>
			<div div="content">
				<h2>hide</h2>
				<p>Hide the matched elements.</p>
			</div>
			<div id="border"></div>
		</div>
     </div>    
</body>
</html>
      

最佳答案

小错别字,您需要更正这一行:

<button div="hide">hide</button>

对此:

<button id="hide">hide</button>

已编辑

 $(document).ready(function() {

   $('h1').click(function() {
     alert('hello');
   })
   $('#hide').click(function() {
     $('p').hide();
   })
 })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>YOOO</h1>
<div id="container">
  <div class="effects">
    <button id="hide">hide</button>
    <div div="content">
      <h2>hide</h2>
      <p>Hide the matched elements.</p>
    </div>
    <div id="border"></div>
  </div>
</div>

关于jQuery "hide"函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31347943/

相关文章:

jquery - 根据字符数动态更改字体大小

android - 100%完成时在android中隐藏通知区域进度条

CSS:隐藏元素但保持宽度(而不是高度)

javascript - 两个选择器在另一个中不显示所选值

wpf - 如何使用 MultiBinding 在上下文菜单中隐藏分隔符?

带有行跨度的 jquery 无表布局

javascript - IE8 的 WYSIHTML5 字符计数器

javascript - 扩展 jsplumb.draggable 拖动行为

jquery - 使用 jquery 添加和删除属性

Jquery .show() 无法在 HTML5 数据描述符上使用 .find() - 需要帮助!