2013-07-19 13 views
2

美好的一天!基本上,我想要一個文本框,當點擊複選框時出現,並在未點擊時消失。這裏是JSFiddle http://jsfiddle.net/GBSZ8/2/,它工作得很好。但是,當我將它保存爲check.php時,即使單擊複選框,文本框也不會顯示。
單擊複選框時會出現一個文本框,可用於jsfiddle,但不適用於我的瀏覽器

<html> 
<head> 
<script> 
    $('#supplied').live('change', function(){ 
     if ($(this).is(':checked')) { 
     $('#date').show(); 
    } else { 
     $('#date').hide(); 
    } 
}); 
</script> 
</head> 
<body> 
    <input type="checkbox" name="supplied" id="supplied" value="supplied" class="aboveage2" /> 

    <ul id="date" style="display:none"> 
     <li><input id="start" name="start" size="5" type="text" class="small" value="1" /></li> 
    </ul> 
</body> 
</html> 


請幫助我。謝謝!

+1

#supplied在您運行.live()調用時不存在。你需要在'.ready()'調用中包裝所有內容...... –

回答

4

你必須在你的文件中包含JQuery。把

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

在你的第一個標籤上方。

隨意更改版本號爲合適或調整URL去jQuery的js文件的本地版本

1

你可能需要將其包裝中的onLoad以及Paarth的答案。

$(document).ready(function() { 
相關問題