我的脚本中有两个javascript函数 myfunction()和 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}
}).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>
submitform()函数调用表单中的osubmit
事件, myfunction()调用onfocus
和onblur
{ {1}}标记。
当我调用 submitform()函数时, myfunction()函数会停止其处理textarea
和onfocus
事件
答案 0 :(得分:0)
只需使用submitform()
代替return submitform()
<form method = "POST" onsubmit = "submitform();" >
答案 1 :(得分:0)
试试这个
<form onsubmit = "submitform();" >
JS
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 );
});
}
答案 2 :(得分:0)
朋友这段代码现在正在运作。
我发现了我的问题
正确的代码如下..
<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>