任何想法为什么这不能在我的PHP文档中工作?当我在jsfiddle上测试时,一切正常.
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$("a").click(function() {
$("div.info").hide();
$("div." + this.className).show();
});
</script>
</head>
<body>
<div class="shipping-container">
<a href="#" class="ups">Show UPS info</a>
<a href="#" class="fedex">Show Fedex info</a>
<div class="ups info" style="display:none">the info for ups</div>
<div class="fedex info" style="display:none">Who let the dogs out</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
你错过了文档就绪处理程序,试试这个:
<script type="text/javascript">
$(function() {
$("a").click(function() {
$("div.info").hide();
$("div." + this.className).show();
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
或者,保留您的script标签,但将其放在</body>标签前面的文档末尾.