简体   繁体   English

javascript确认不适用于Chrome或IE,但适用于Firefox

[英]javascript confirm works not working in chrome or IE, but works in Firefox

I tried doing a search in stackoverflow. 我试图在stackoverflow中进行搜索。 There were topics on this issue. 有关于此问题的主题。 I tried several of the fixes that were close to mine, but none of the worked. 我尝试了一些接近我的修复程序,但没有一个起作用。 I also tried Googling the topic, but anything I tried did not work. 我也尝试使用Google搜索该主题,但是尝试执行的任何操作均无效。

Any help is appreciated. 任何帮助表示赞赏。

Here is the situation, this javascript confirm works, meaaning the confirm dialogue appears and is functional in Firefox, but not work in IE or Chrome, meaning the confirm dialogue box does not appear and the code moves to the appropriate next page as if it were confirmed: 在这种情况下,此javascript确认起作用,意味着确认对话框出现并在Firefox中起作用,但在IE或Chrome中不起作用,这意味着不会出现确认对话框,并且代码移至相应的下一页,就像确认:

function confirmReserve($checkin, $checkout, $nights, $points) { 

    var $in =new Date($checkin*1000);
    var $out =new Date($checkout*1000);
    if (confirm("Your Reservation Details:  \n\nCheck-In Date:  " + $in.toLocaleFormat('%B %d, %Y') + "\nCheck-Out Date:  " + $out.toLocaleFormat('%B %d, %Y')  + "\nTotal Nights:  " + $nights + "\nTotal points:  " + $points + "\n\nClick OK to process reservation.")) {
    return true; 
 }  else {
    return false;
 } 

But, this one works in all three: 但是,这一项在所有三个方面都有效:

function confirmDelete() { 
if (confirm("Click OK to confirm cancellation of your reservation.")) {
    return true; 
 }  else {
    return false;
 } 
} 

It is the same PHP program, same browsers. 它是相同的PHP程序,相同的浏览器。 Here is the HTML to the one that does not work: 这是无效的HTML:

<form method="post" onsubmit="return confirmReserve('<?php echo $InDate;?>', '<?php echo $OutDate;?>', '<?php echo $totalNights;?>', '<?php echo $totalPoints;?>')" action="reservationConf.php">

Here is the HTML for the one that does work: 这是可以正常工作的HTML:

<form method="post" onsubmit="return confirmDelete()" action="deletereservation.php?ReservationID=' . $Reservation['ReservationID'] . '">

try to put before your function that code below: 尝试将以下代码放在函数之前:

    var monthNames = ["January", "February", "March", "April", "May", "June",
  "July", "August", "September", "October", "November", "December"
];

Date.prototype.toLocaleFormat = Date.prototype.toLocaleFormat ||     
    function(pattern) {
        return pattern.replace(/%Y/g, this.getFullYear())
           .replace(/%m/g, (this.getMonth() + 1))
           .replace(/%B/g, monthNames[this.getMonth()])
           .replace(/%d/g, this.getDate()); 
};

The issue is that Chrome and IE are missing toLocaleFormat function, according to JavaScript function not working on Chrome & IE but works on FireFox 问题是Chrome和IE缺少toLocaleFormat函数,因为JavaScript函数无法在Chrome&IE上运行,但在FireFox上有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM