2014-11-03 65 views
0

我使用以下脚本在用户向服务器提交数据时禁用按钮。 它与Firefox正常工作,但不适用于Chrome。当你在chrome上提交时,按钮会变成发送的数据,但是当你检查数据库时你不会在那里找到它,但是在firefox上它可以很好地工作,当按钮变成发送的数据时,你检查数据库并在那里找到它按钮数据提交到服务器的更改

<script language="javascript"> 
$(function(){ 
    $(".btn-style1").click(function(){ 
     $(this).val('data sent'); 
     $(this).attr('disabled', 'disabled'); 
    }); 
}); 
</script> 

回答

2

将属性值设置为true/false而不是禁用。它将在所有浏览器上运行。检查下面的代码。在这里我将属性值更改为true,而不是禁用。通过执行下面的代码片段来检查它。我还添加了表单,以便您可以通过单击按钮来检查表单提交。

$(function(){ 
 
$(".btn-style1").click(function(){ 
 
    $(this).val('data sent'); 
 
    $(this).attr('disabled', true); 
 
    return true; 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<form action="http://stackoverflow.com/posts/xxx/edit"> 
 
    
 
<input type="hidden" name="a" value="abc"/> 
 
<button type="submit" class='btn-style1' >Click</button> 
 
</form>

+0

它仍然是相同的,在firefox工作,但不是镀铬 – blay 2014-11-03 09:36:13

+0

其能够禁用按钮,但不能在Chrome发送数据 – blay 2014-11-03 09:41:10