javascript函数不工作?
我的脚本中有两个javascript函数myfunction和submitformjavascript函数不工作?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我的脚本中有两个javascript函数myfunction和submitform <script> var intervalID = 0; function myFunction(interval) { if(interval == 1) { if(intervalID != 0) { window.clearInterval(intervalID); intervalID = 0; } } else if(intervalID ==
<script>
var intervalID = 0;
function myFunction(interval) {
if(interval == 1) {
if(intervalID != 0) {
window.clearInterval(intervalID);
intervalID = 0;
}
}
else if(intervalID == 0){
intervalID = window.setInterval(function () {
getdetails();
$('.View').load('alert.php').fadeIn("slow");
}, 1000);
}
}
function getdetails(){
$.ajax({
type: "POST",
url: "detail.php"
}).done(function( result ) {
$("#msg").html( result );
});
}
function submitform(){
var comment = $("#comment").val();
var alertid = $("#alertid").val();
$.ajax({
type: "POST",
url: "analytic.php",
data:{cmt:comment,alert_id:alertid}
}).done(function( result ) {
$("#msg").html( result );
});
return false;
}
</script>
<form method = "POST" onsubmit = "return submitform();" >
<textarea onFocus = "myFunction(1)" onBlur = "myFunction(0)" style="margin: 0px 0px 8.99305534362793px; width: 570px; height: 50px;" rows = "6" cols = "40" id = "comment"></textarea> <br />
<input type = "hidden" placeholder="Enter Maximium 100 Words" id = "alertid" value = "102" />
<input type = "submit" name = "submit" value = "Comment" />
</form>
表单中osubmit事件的submitform函数调用和textarea标记中onfocus和onblur的myfunction调用。
当我调用submitform函数时,myfunction函数停止处理onfocus和onblur事件只需使用submitform而不是返回submitform
试试这个
<form onsubmit = "submitform();" >
朋友们,这段代码现在正在运行。 我发现了我的问题。 按如下所示更正代码
<script>
var intervalID = 0;
function myFunction(interval) {
if(interval == 1) {
if(intervalID != 0) {
window.clearInterval(intervalID);
intervalID = 0;
}
}
else if(intervalID == 0){
intervalID = window.setInterval(function () {
getdetails();
$('.View').load('alert.php').fadeIn("slow");
}, 1000);
}
}
function getdetails(){
$.ajax({
type: "POST",
url: "detail.php"
}).done(function( result ) {
$("#msg").html( result );
});
}
function submitform(){
var comment = $("#comment").val();
var alertid = $("#alertid").val();
$.ajax({
type: "POST",
url: "analytic.php",
data:{cmt:comment,alert_id:alertid}
});
return false;
}
</script>
<form method = "POST" onsubmit = "return submitform();" >
<textarea onFocus = "myFunction(1)" onBlur = "myFunction(0)" style="margin: 0px 0px 8.99305534362793px; width: 570px; height: 50px;" rows = "6" cols = "40" id = "comment"></textarea> <br />
<input type = "hidden" placeholder="Enter Maximium 100 Words" id = "alertid" value = "102" />
<input type = "submit" name = "submit" value = "Comment" />
</form>
错误控制台中有错误吗?@JeremyJStarcher没有控制台中没有错误。
function submitform(){
var comment = $("#comment").val();
var alertid = $("#alertid").val();
$.ajax({
type: "POST",
url: "analytic.php",
data:{cmt:comment,alert_id:alertid}
}).done(function( result ) {
$("#msg").html( result );
});
}
<script>
var intervalID = 0;
function myFunction(interval) {
if(interval == 1) {
if(intervalID != 0) {
window.clearInterval(intervalID);
intervalID = 0;
}
}
else if(intervalID == 0){
intervalID = window.setInterval(function () {
getdetails();
$('.View').load('alert.php').fadeIn("slow");
}, 1000);
}
}
function getdetails(){
$.ajax({
type: "POST",
url: "detail.php"
}).done(function( result ) {
$("#msg").html( result );
});
}
function submitform(){
var comment = $("#comment").val();
var alertid = $("#alertid").val();
$.ajax({
type: "POST",
url: "analytic.php",
data:{cmt:comment,alert_id:alertid}
});
return false;
}
</script>
<form method = "POST" onsubmit = "return submitform();" >
<textarea onFocus = "myFunction(1)" onBlur = "myFunction(0)" style="margin: 0px 0px 8.99305534362793px; width: 570px; height: 50px;" rows = "6" cols = "40" id = "comment"></textarea> <br />
<input type = "hidden" placeholder="Enter Maximium 100 Words" id = "alertid" value = "102" />
<input type = "submit" name = "submit" value = "Comment" />
</form>