将输入转换为jQuery中的链接 [英] convert input to link in jquery
问题描述
此刻脚本如下所示:
- 单击链接,使输入可见,以编辑链接
- 单击下一步/在链接之前,通过使输入可见来编辑链接
我希望在链接上单击一次时不进行编辑,而是在新窗口中打开页面,并单击双击以进行编辑.
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.
这是脚本:
推荐答案
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中的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!