0
我有一个div什么样的按钮(.butt),当我点击它,它应该防止href重定向和打开输入。它的剂量工作,它仍然重定向,当我从重定向返回输入出现,但是当我按下输入时,它仍然重定向。我怎样才能防止href重定向onclick
我该如何做到这一点,以便当我按下div时禁用重定向,并让我在输入中插入一个值以更改值?
var x;
var h = 0; // blur fires multiple times, use h to count and fire once
var url = 'up.php';
$(".butt").on('click', function(event) {
event.preventDefault();
$(".tk").on('click', function(d) {
\t d.stopPropagation();
\t var x = $(d.target);
\t x.html('<input id="edit2" style="width: 40px;" value="'+x.text()+'">');
\t var this_id = x.context.id;
\t
\t $("#edit2").on('blur', function(d) {
\t \t if (h < 1) {
\t \t \t h = h+1;
\t \t \t d.stopPropagation();
\t \t \t
\t \t \t $(d.target.parentElement).text(d.target.value);
\t \t \t
\t \t \t $.get(url, {id: this_id, value: d.target.value})
\t \t \t \t .done(function(d){ if(d == undefined || d != 1) { alert('Something went wrong, check your data and results. '+d);}})
\t \t \t \t .fail(function(d){ alert('error');});
\t \t \t $("#edit2").off('blur');
\t \t }
\t \t
\t \t
\t }); \t
\t h = 0;
});
});
.butt{width:15px;height:15px; background-color:red;border-radius: 50%;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="butt"> </div>
<a href="http://www.google.com" class="tk">click</a>