链接到小提琴:http://jsfiddle.net/FvMYz/2858/
小提琴上的代码有效,但是当我在.html文件上运行时,根本没有显示任何内容。
html页面中的代码
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<tr>
<td>
<select id="pay-type" name="form_select" class="form-control" onchange="test()">
<option value="hand">Cash on Hand</option>
<option value="palawan">Palawan Express</option>
<option value="paypal">Paypal</option>
<option value="bdo">BDO Master Card</option>
<option value="xoom">Xoom.com</option>
</select>
</td>
<td>
<div id="hand" class="pay-type" style="display:none"> You have selected onhand </div>
<div id="palawan" class="pay-type" style="display:none"> You have selected palawan </div>
<div id="paypal" class="pay-type" style="display:none"> You have selected paypal </div>
<div id="bdo" class="pay-type" style="display:none"> You have selected BDO </div>
<div id="xoom" class="pay-type" style="display:none"> You have selected xoom </div>
</td>
</tr>
</table>
</html>
jquery.js中的代码
$(function test()
{
$('#pay-type').change(function(){
$('.pay-type').hide();
$('#' + $(this).val()).show();
});
});
我不是很擅长jquery所以我真的不知道我做错了什么。与同样思考的其他问题相比,我的情况有点不同。
答案 0 :(得分:2)
您的代码使用$
功能。这取决于jQuery,但你还没有加载jQuery。你可以从the jQuery website获得它。
为避免混淆,您应将现有的jquery.js
重命名为描述其目的的内容(例如show-pay-type.js
),而不是其所依赖的库。