gpt4 book ai didi

javascript - IE 7 问题 : jquery click to edit Not working

转载 作者:行者123 更新时间:2023-11-28 20:27:07 24 4
gpt4 key购买 nike

我的上一篇文章有​​效果。它有一个按钮。当我单击它时,创建一个能够单击并编辑并重命名该字段的 Div 。此效果在除 IE7 之外的所有浏览器中均有效。我想知道为什么以及是否有任何方法可以通过 IE 7 提供此支持。

Here is Live demo in js fiddle

我的代码:

HTML

<button id="createDiv">Start</button>
<div id="results"></div>

CSS

    #createDiv, #results span { cursor: pointer; }
#results div {
background: #FFA;
border: 1px solid;
width:auto;
}
#results input[type=text] {
border: none;
display: none;
outline: none;
}
.clickToCancleIcon{
float: right;

}

.new-folder{
height:30px;
float:left;

}

JS

    //  Call for document .onload event
$(function() {
// Normal Click event asignement, same as $("#createDiv").click(function
$("#createDiv").on("click", function(e) {
// Simply creating the elements one by one to remove confusion
var newDiv = $("<div />", { class: "new-folder" }), // Notice, each child variable is appended to parent

newInp = $("<input />", { name: "inpTitle[]",style:"display:block ;float:left; border:solid 1px #fa9a34", type: "text", value: "Unnamed Group", class: "title-inp" }).appendTo(newDiv),

newSpan = $("<span />", { id: "myInstance2",style:"display:none; float:left;", text: "Unnamed Group", class: "title-span" }).appendTo(newDiv),


clickToCancle = $("<a />", { text: "X", class: "clickToCancleIcon" }).appendTo(newDiv),
clickToEdit = $("<span />", { text: "Edit" , style:"float:right; margin:0px 5px;" ,



class: "clickToEdit" }).appendTo(newDiv);


// Everything created and seated, let's append this new div to it's parent
$("#results").append(newDiv);
});

// the following use the ".delegate" side of .on
// This means that ALL future created elements with the same classname,
// inside the same parent will have this same event function added
$("#results").on("click", ".new-folder .title-span", function(e) {
// This hides our span as it was clicked on and shows our trick input,
// also places focus on input
$(this).hide().prev().show().focus();
});
$("#results").on("blur", ".new-folder .title-inp", function(e) {
// tells the browser, when user clicks away from input, hide input and show span
// also replaces text in span with new text in input
$(this).hide().next().text($(this).val()).show();
});
// The following sures we get the same functionality from blur on Enter key being pressed
$("#results").on("keyup", ".new-folder .title-inp", function(e) {
// Here we grab the key code for the "Enter" key
var eKey = e.which || e.keyCode;
if (eKey == 13) { // if enter key was pressed then hide input, show span, replace text
$(this).hide().next().text($(this).val()).show();
}
});
})

最佳答案

看起来它指向这行代码

var newDiv = $("<div />", { class: "new-folder" }),

class 更改为带引号的 "class"

var newDiv = $("<div />", { "class": "new-folder" }),

并对其他具有类的行执行相同的操作。

关于javascript - IE 7 问题 : jquery click to edit Not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17176958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com