我有一個表單用於發佈評論(一個文本框和一個textarea +提交按鈕)。我希望表單最初不可見,只顯示一個'showform'鏈接窗體可見以及顯示「隱藏表格」鏈接。單擊「隱藏表格」鏈接時,& hideform link
表單應該變爲不可見,並且showform鏈接應該再次可見。 我想這使用jquery隱藏和顯示元素
<html>
<head>
<title>formopen demo</title>
<link href="formopen.css" type="text/css" rel="stylesheet">
</head>
<script src="jquery-1.4.2.js"></script>
<script src="formopen.js"></script>
<body>
<div class="myjsdemo">
<a href="#" class="showaddcommentformlink">show add commentform</a>
<a href="#" class="hideaddcommentformlink">hide add commentform</a>
<div class="form">
<input type="text" value="" name="myinput" id="myinput"/>
<textarea name="content" rows="2" cols="20" id="content" > </textarea>
</div>
</div>
</body>
</html>
formopen.css
.myjsdemo .form{display:none;}
.myjsdemo .hideaddcommentformlink{display:none;}
formopen.js
$(function(){
$('.myjsdemo.showaddcommentformlink').click(
function(){
$(this).hide();
$('.myjsdemo.hideaddcommentformlink').show();
$('.myjsdemo.form').show();
return false;
}
);
$('.myjsdemo.hideaddcommentformlink').click(
function(){
$(this).hide();
$('.myjsdemo.showaddcommentformlink').show();
$('.myjsdemo.form').hide();
return false;
}
);
});
然而,當我點擊鏈接後沒有任何反應......我的JavaScript的非常小知識..如果有人可以糾正這個代碼中的任何錯誤,這將是一個很好的幫助..
我將所有文件放在同一個目錄中,並在Firefox中打開html文件。
謝謝