我想知道为什么这两个按钮会点击按钮?
<script type="text/javascript">
$(document).ready("#testbutton").click(function () {
$.ajax({
url: '@Url.Action("RenderBlogComments","Home")',
success: function (data) {
// your data could be a View or Json or what ever you returned in your action method
// parse your data here
alert(data);
}
});
});
</script>
<input type="submit" name="testbutton" value="submit" id="testbutton" />
<input type="submit" name="testbutton" value="submit" id="testbutton2" />
答案 0 :(得分:2)
试
$(document).ready(function(){
$(""#testbutton"").click(function () {
$.ajax({
url: '@Url.Action("RenderBlogComments","Home")',
success: function (data) {
// your data could be a View or Json or what ever you returned in your action method
// parse your data here
alert(data);
}
});
});
});
答案 1 :(得分:1)
使用此解决方案,只有第一个按钮会触发ajax调用。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#testbutton").click(function() {
$.ajax({
url: 'http://www.google.de',
success: function (data) {
// your data could be a View or Json or what ever you returned in your action method
// parse your data here
alert(data);
}
});
});
});
</script>
</head>
<body>
<input type="submit" name="testbutton" value="submit" id="testbutton" />
<input type="submit" name="testbutton" value="submit" id="testbutton2" />
</body>
</html>