上网查过以后我写了一段测试代码,但始终不行,怎么回事?
<html>
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
</head><body>
<script>
$("#test").attr("disabled", "disabled");
</script> <button id="test">推荐发起</button></body>
</html>
<html>
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
</head><body>
<script>
$("#test").attr("disabled", "disabled");
</script> <button id="test">推荐发起</button></body>
</html>
<script>
$("#test").attr("disabled", "disabled");
</script>你的元素还没加载完 。
jQuery(function($) {
$("#test").attr("disabled", "disabled");
});
</script>
一,把js放到body下面,等页面渲染完后执行
二,$(function(){
//你的代码
}),放到里面,会等页面渲染完后才执行
<script>
$(function(){
$("#test").attr("disabled", "disabled");
});
</script>