Javascript 防止多次单击按钮的jQuery不起作用
我有一个表单,当用户多次点击按钮时,数据也会在数据库中保存多次。我这样做是为了限制多次点击,以防止这是我的代码,但它仍然不工作Javascript 防止多次单击按钮的jQuery不起作用,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我有一个表单,当用户多次点击按钮时,数据也会在数据库中保存多次。我这样做是为了限制多次点击,以防止这是我的代码,但它仍然不工作 <head> <link href="~/Contents/css/style1.css" rel="stylesheet" /> <script> $('form').submit(function () { $(this).find(':submit').attr('disa
<head>
<link href="~/Contents/css/style1.css" rel="stylesheet" />
<script>
$('form').submit(function () {
$(this).find(':submit').attr('disabled', 'disabled');
});
</script>
</head>
<div class="w3layouts_main wrap">
<h1 class="agile_head text-center" style="color: #e60053 ;font-family :'Comic Sans MS'">Share Your Experience</h1>
<form action="#" method="post" class="agile_form" id="form1">
<h1 style="color: white; font-size: large">1. Quality of Service. </h1>
<h2 style="color : #0086ce" >How satisfied were you with our Service?</h2>
<!--Star Raiting-->
<span class="SmileyRating" data-name="QualityOfService">
</span>
<br />
<!--Star Raiting End-->
<h1 style="color: white; font-size: large">2. Quality of Food. </h1>
<h2 style="color : #0086ce">How satisfied were you with our Food?</h2>
<span class="SmileyRating" data-name="QualityOfFood">
</span>
<br />
<!--Star Raiting End-->
<h1 style="color: white; font-size: large">3. Cleanliness of Lounge. </h1>
<h2 style="color : #0086ce">How satisfied were you with Marhaba Lounge Cleaning?</h2>
<span class="SmileyRating" data-name="CleanlinessOfLounge">
</span>
<br />
<!--Star Raiting End-->
<h1 style="color: white; font-size: large">4. Friendliness of Staff. </h1>
<h2 style="color : #0086ce">How satisfied were you with our Staff?</h2>
<span class="SmileyRating" data-name="FriendlinessOfStaff">
</span>
<br />
<!--Star Raiting End-->
<h1 style="color: white; font-size: large">5. Overall experience. </h1>
<h2 style="color : #0086ce">How satisfied were you with Marhaba Lounge?</h2>
<span class="SmileyRating" data-name="OverAllExperience">
</span>
<br />
<!--Star Raiting End-->
<h3 style="color: white; font-size: large">Valuable Suggestions.</h3>
<textarea placeholder="Additional comments" class="w3l_summary" name="Comments"></textarea>
<input id="formSubmit" type="submit" value="Submit" class="agileinfo" style= "background-color: white; color: #e60053 " onmouseover="this.style.backgroundColor = '#e60053', this.style.color = 'white' " onmouseout="this.style.backgroundColor = 'white', this.style.color = '#e60053'" />
</form>
</div>
$('form')。提交(函数(){
$(this.find(':submit').attr('disabled','disabled');
});
分享你的经验
1.服务质量。
您对我们的服务有多满意?
2.食品质量。
你对我们的食物满意吗?
3.休息室的清洁。
您对Marhaba休息室的清洁有多满意?
4.工作人员的友善。
您对我们的员工有多满意?
5.总体经验。
您对马尔哈巴休息室的满意度如何?
有价值的建议。
实现我想要的脚本是这样的
<script>
$('form').submit(function () {
$(this).find(':submit').attr('disabled', 'disabled');
});
</script>
$('form')。提交(函数(){
$(this.find(':submit').attr('disabled','disabled');
});
我做错了什么?如何在visual studio中调试jQuery?如果您使用的是jQuery v1.6较小版本,那么这里将提供一个解决方案
$('form').submit(function() {
$(this).find("input[type='submit']").attr('disabled','disabled');
});
对于jqueryv1.6+
$('form').submit(function() {
$(this).find("input[type='submit']").prop('disabled',true);
});
希望这能对您有所帮助。如何调试它,以确认它是否正常工作,bcoz网络现在速度很快,我无法检查this@ArhamKhan在浏览器控制台中放置一个调试器并检查它。@ArhamKhan:您可以使用Chrome开发工具,在“网络”选项卡中,您可以随心所欲地减慢网络速度。为什么不改进project的体系结构,以防止多次单击,并限制在数据库中重复插入?