【发布时间】:2015-05-17 12:22:39
【问题描述】:
function f(){
$("#main").focus();
}
$(document).ready(function(e) {
$("#main").focus();
$("button").hide();
$("li").live("dblclick", function(){
var node = document.createElement("ul");
var node_li = document.createElement("li"); // Create a <li> node
var textnode = document.createTextNode(""); // Create a text node
node_li.appendChild(textnode);
node.appendChild(node_li);
// Append the text to <li>
//document.getElementById("main").appendChild(node);
$(this).append(node);
//alert($(this).parent().children().index(this));
})
$('li').live('keypress',function(e){
var p = e.which;
if(p==9){
var node = document.createElement("ul");
var node_li = document.createElement("li"); // Create a <li> node
var textnode = document.createTextNode(""); // Create a text node
node_li.appendChild(textnode);
node.appendChild(node_li);
// Append the text to <li>
//document.getElementById("main").appendChild(node);
$(this).append(node);
}
});
});
// $(".fb li").live
function li_new(){
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
</script>
<p>Press "Enter for next lile" Double click on line for Sub-line.</p>
<div class="currentlist" contenteditable="true" id="main" onBlur="f()" style="height:2000px;">
<li></li>
</div>
<input type="tel" style="position:fixed; margin-left:10000px"/>
<div id="c"></div>
我使用上面的代码来创建项目符号。双击
请给出一个添加列表和子列表的解决方案,像 MS Word 一样按 Enter 键和 Tab 键。如果内容可编辑选项不符合我的要求,请提供解决方案,我该如何创建和编辑项目符号和子项目符号并赋予它们样式。
注意:我不想使用粗体、斜体等其他选项。只需要使用 Enter 和 Tab 键的 Bullet 和 Sub-bullet 选项。
【问题讨论】:
-
首先,不要使用
.live。使用.on()。接下来,在小提琴中发布您的代码。
标签: javascript jquery html css