小编Som*_*pub的帖子

如何防止href重定向onclick

我有一个div,它的行为就像一个button(.butt),当我单击它时,它应防止href重定向并打开输入。它工作正常,它仍然重定向,当我从重定向返回时,输入出现,但是当我按下输入时,它仍然重定向。

我怎样才能使它在我按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) { 
	d.stopPropagation();
	var x = $(d.target); 
	x.html('<input  id="edit2" style="width: 40px;" value="'+x.text()+'">'); 
	var this_id = x.context.id;
	
	$("#edit2").on('blur', function(d) { 
		if (h < 1) {
			h = h+1;
			d.stopPropagation();
			
			$(d.target.parentElement).text(d.target.value);
			
			$.get(url,  {id: this_id, value: d.target.value})
				.done(function(d){ if(d == undefined || d != 1) { alert('Something went wrong, check your data and results. …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery redirect href

2
推荐指数
1
解决办法
4619
查看次数

标签 统计

href ×1

html ×1

javascript ×1

jquery ×1

redirect ×1