我该如何处理jQuery中锚文本值更改为“"的情况? [英] How can I deal with a case in jQuery where an anchor's text value is changed to ""?

查看:117
本文介绍了我该如何处理jQuery中锚文本值更改为“"的情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码: Jsfiddle

  1. 我有一个表单,可以通过双击链接或在div内部单击a来编辑a文本值.
  2. Onblur,将输入框中的值(根据1.中的条件显示)分配给a的文本值.
  1. I have a form where the a text values can be edited by dblclicking on the link, or clicking inside the div the a is inside.
  2. Onblur, the value in the input box that is shown on the conditions in 1. is assigned to the text value of the a.

问题:当您将输入保留为空并将其模糊时,它将a的文本设置为"".此时,其周围的div折叠起来,用户无法访问.

The Problem: when you leave the input empty and blur it, it sets the a's text to "". At this point the div around it collapses and becomes inaccessible to the user.

如何防止这种崩溃的发生?

How can I prevent this collapse from happening?

推荐答案

只要这样做,您的问题就会得到解决.

Just do this way, your problem will be sorted out.

在模糊处理中,只需检查值长度为零,然后显示输入字段,否则显示超链接.

On blur, just check the value length is zero then show the input field else show the hyperlink.

$('#url0, #url1').each(
    function(index, element){
        $(element).blur(function(){
            if ($(this).val().length == 0)
                $(this).show();
            else
                $(this).hide().prev().show().find('a').html(this.value);
        });
    }    
);

请参考 实时演示

Refer this LIVE DEMO

这篇关于我该如何处理jQuery中锚文本值更改为“"的情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆