0

我有以下代码:

<script type="text/javascript">

    function editLabel(source) {
        source.innerHTML = '<input type="text" value="' + source.innerHTML + '"/>';
        source.onclick = null;
        source.children[0].focus()
    }
    function setLabel(source) {

        if (source.children[0].value != '') {
            source.onclick = function () { editLabel(source); };
            source.innerHTML = source.children[0].value;
        }

    }

然后在我的asp标签中:

 <asp:Label ID="lblName" runat="server" onfocusout="setLabel(this);" onclick="editLabel(this);" Text='<%# Bind("GroupDescription") %>'></asp:Label>

这在 Chrome 和 IE 中运行良好,但在 Firefox 中不起作用。

这是因为 Firefox 只支持 onblur。

我试图将 onblur 添加到标签和文本框,但它不起作用。

我能做什么?

谢谢

4

1 回答 1

0

查看 jQuery,并将函数绑定到事件。即检查悬停、模糊和焦点。如果你想做任何真正的 Web 开发,像 jQuery 这样的框架是必要的。

http://api.jquery.com/hover/

http://api.jquery.com/blur/

http://api.jquery.com/focus/

例如,请参见此处:http: //jsfiddle.net/turiyag/fQV3p/

$("#blurry").hover(function() {
    log("Hover In!");
}, function(){
    log("Hover Out!");
});
$(":text").blur(function() {
    log("Blurred from textbox with value: " + $(this).val());
});
$(":text").focus(function() {
    log("Focus given to textbox with value: " + $(this).val());
});
于 2013-02-06T14:06:07.187 回答