jQuery
小さなアイコンをクリックすると開くメニューを作成しました。このメニューには、クリック可能ないくつかのリンクと、いくつかの js アクションを実行して同じメニュー内に新しいテキスト ボックスを作成する 1 つのリンクが含まれています。しかし、リンクをクリックすると、メニューが自動的に閉じます。したがって、テキストボックスが表示されていても、そのアイコンをもう一度クリックしてメニューを表示するまで表示されません。
ここにデモがあります: http://jsfiddle.net/W2exq/1/
jQuery
メニューの表示と非表示、およびテキストボックスの表示にいくつかのコードを使用しました。では、メニューの外をクリックして閉じない限り、メニューを開いたままにするにはどうすればよいでしょうか? 他に必要なものがあれば教えてください。
HTML:
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js></script>
<link rel="stylesheet" type="text/css" href="http://tharunjose.com/stack/style.css" />
</head>
<div class="notes">
<div class="noteTooltip">
This link is for the special purpose of the main site.<hr />
<a class="noteEdit" id="add_btn" href="#">Edit note</a>
<a class="noteTrash" href="#"></a>
</div>
</div>
CSS:
.notes{
position:relative;
width:16px;
height:16px;
margin:0 auto;
background:url(http://tharunjose.com/stack/images/icons.png) no-repeat scroll -228px -34px transparent;
}
.notes:hover{
cursor:pointer;
background-position:-207px -34px;
}
.noteTooltip{
display:none;
position:absolute;
top:25px;
left:-10px;
width:130px;
text-align:left;
line-height:18px;
border:2px solid #363636;
z-index:9999;
background:#fbfbfb;
-webkit-border-radius:3px;
-moz-border-radius:3px;
border-radius:3px;
padding:10px 10px 6px 10px;
cursor:auto;
}
.noteTooltip:before{
content:'';
position:absolute;
top:-10px;
left:10px;
width:0;
height:0;
border-left:5px solid transparent;
border-right:5px solid transparent;
border-bottom:8px solid #000;
z-index:9999;
}
.noteEdit{
color:#3ba5d5;
text-decoration:none;
float:left;
}
.noteTrash{
display:block;
float:right;
padding:6px;
background:url(http://tharunjose.com/stack/images/icons.png) no-repeat scroll -20px -106px transparent;
}
JS:
$(document).ready(function() {
$(document).click(function(e) {
$(".createNew, .username, .notes, .pageHelp, .buttons").removeClass("open");
});
$(".createNew, .username, .notes, .pageHelp, .buttons").click(function(e) {
e.stopPropagation(); // this prevents it closing via document.click
$(this).toggleClass("open");
});
var handler_func = function () {
var i = (typeof this.rel != 'undefined') && (this.rel - 0) == this.rel ? this.rel : 0;
var e = document.createElement('input');
e.type='text';
e.width=40;
e.name = 'added'+i;
this.rel = i+1;
this.parentNode.appendChild(e);
return false;
}
var add_btn = document.getElementById('add_btn');
if(add_btn.attachEvent)
add_btn.attachEvent('onClick', handler_func);
else if(add_btn.addEventListener) //Firefox & company
add_btn.addEventListener('click', handler_func, false);
});
</p>