【发布时间】:2014-05-03 05:39:24
【问题描述】:
我可能已经盯着这个太久了,并且遗漏了一些明显的东西,但是:为什么这在 JSFiddle 中工作正常,而不是在我上传时??
测试网站上会显示最后的警报,但无论如何“showthis”也是可见的。
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Form Field</title>
<script type="text/javascript" src="scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="scripts/showfield.js"></script>
</head>
<body>
<input type="checkbox" name="checkbox" id="checkbox" value="checkbox" />
<br />
<input id="showthis" name="showthis" size="50" type="text" value="text here"/>
</body>
</html>
jQuery(我已经下载了一个缩小的 jQuery 1.11.0 ,这是在 JSFiddle 中工作的)
//hide field by default
$('input[name="showthis"]').hide();
//show it when the checkbox is clicked
$('input[name="checkbox"]').on('click', function(){
if ( $(this).prop('checked') ) {
$('input[name="showthis"]').fadeIn();
}
else {
$('input[name="showthis"]').hide();
}
});
// the alert is showing fine
alert ("hello");
JSFiddle http://jsfiddle.net/DLQY9/
【问题讨论】:
-
你是否在 dom 就绪处理程序中添加了脚本