将输入转换为jQuery中的链接 [英] convert input to link in jquery

查看:106
本文介绍了将输入转换为jQuery中的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻脚本如下所示:

  1. 单击链接,使输入可见,以编辑链接
  2. 单击下一步/在链接之前,通过使输入可见来编辑链接

我希望在链接上单击一次时不进行编辑,而是在新窗口中打开页面,并单击双击以进行编辑.

i want when you click one time on the link not to edit but to open the page in new window, and when you click double to edit.

这是脚本:

jsfiddle-代码

推荐答案

http:////jsfiddle.net/jaspermogg/pFyNY/1/-您可以双击div进行编辑,或者单击链接打开.那是你想要的吗?

http://jsfiddle.net/jaspermogg/pFyNY/1/ - you can double click the div to edit, or single click the link to open. That what you wanted?

$('.a0').dblclick(function(e){
    e.preventDefault();
    $(this).parent().find('input').val($(this).find('a').text()).show().focus();
    $(this).hide();
})

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

这是一个jsFiddle,它将a的href更改为您编辑的值,以防万一,这是您接下来要尝试的操作:-)

And here's a jsFiddle that changes the href of the a to the value you edited it to, just in case that's what you're trying to do next :-) http://jsfiddle.net/jaspermogg/pFyNY/2/

这是满足您需要的jsFiddle- http://jsfiddle.net/jaspermogg/pFyNY /5/

Here's the jsFiddle that does what you want - http://jsfiddle.net/jaspermogg/pFyNY/5/

JS-

$('.a0 a').click(function(){

    var href = $(this).attr('href');

    // Redirect only after 500 milliseconds (CHANGE THE 500 IN THE CODE TO DETERMINE HOW LONG THE USER GETS TO DBLCLICK)
    if (!$(this).data('timer')) {
       $(this).data('timer', setTimeout(function () {
          window.location = href;
       }, 500));
    }
    return false; // Prevent default action (redirecting)
});

$('.a0').dblclick(function(){
    clearTimeout($(this).find('a').data('timer'));
    $(this).find('a').data('timer', null);

    $(this).parent().find('input').val($(this).find('a').text()).show().focus();
    $(this).hide();
})

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

> Jquery在Href上创建双击事件

这篇关于将输入转换为jQuery中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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