javascript - HTML 中 Javascript 函数的问题

标签 javascript html linux

我在 HTML 头部的 Javascript 中有这个函数定义:

function cancel()
{
  alert("in cancel");   
  my_url=/"/html/some_body.html/";
  parent.body.location.href=my_url;
}

当我在正文中使用此语句调用它时:

echo "<input type=button value=Next"
echo "       onClick='cancel();'>"`

它给了我这个错误:

SCRIPT5007:属性“取消”的值为 null 或未定义,而不是 Function 对象

请帮助我,因为我已经尝试解决这个问题好几天了。

非常感谢您提前回复。

这是完整的 HTML:

#----------------------------------------------------------------------------
# get_argv
#----------------------------------------------------------------------------
get_arguments()
{
  Code to get arguments


}

#----------------------------------------------------------------------------
# make_html_header
#----------------------------------------------------------------------------
make_html_header()
{

echo "Content-type: text/html"
echo
echo "
<html>
<head>
<meta http-equiv=Expires content=0>
<title>Some Title </title>
    <script language=JavaScript>

function select_obj()
{
   var some_var=/"/";
   alert("in select obj");
   for (i = 0; i < document.envir.group.length; i++) {
     if (document.envir.group[i].checked == true ) {
     some_var=document.envir.group[i].value;

     }
   }

   if ( some_var != /"/"){
      my_url=/"/cgi-bin/$PGMNAME?module=${MODULE}\&branch=/" + seme_var;
      parent.body.location.href=my_url;
   }
}

function cancel()
{
   alert("in cancel");
   my_url=/"/html/f_body.html/";
   parent.body.location.href=my_url;
}

</script>

<base target=body>
</head>
"

echo "<body class=main>"
}


#----------------------------------------------------------------------------
# make_html_footer
#----------------------------------------------------------------------------
make_html_footer()
{
  echo "</body>"
  echo "</html>"
}

#----------------------------------------------------------------------------
# get_parameters
#----------------------------------------------------------------------------
get_parameters()
{
  make_html_header

  Logic to create radio buttons and then depending on what's selected go to the next HTML

  echo "<br>"
  echo "<input type=button value=Back"
  echo "       onClick='cancel();'>"
  echo "<input type=button value=Next"
  echo "       onClick='select_obj();'>"
  make_html_footer
}

#----------------------------------------------------------------------------
# main
#----------------------------------------------------------------------------

get_arguments
get_parameters

出于隐私原因删除了一些代码。

最佳答案

试试这个:

function cancel(){              
   window.location.href="/html/some_body.html";
}

确保在 html head 标签中添加 js 代码

<head>
        <script>

        function cancel(){              
           window.location.href="/html/some_body.html";
        }

        </script>
</head>

还有你的 PHP

<?php

    echo "<input type=\"button\" onClick=\"cancel()\" value=\"Click\" />";

?>

关于javascript - HTML 中 Javascript 函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548012/

相关文章:

c++ - 进行异步调用后删除 asio 套接字

javascript - 为什么我的计时器条会停在某个点?

javascript - 如何将这个参数传递给这个函数?

html - 使静态图像可滚动

html - 如何使用CSS更改iframe src

java - 是否可以将ldap服务器直接连接到Android手机?

javascript - 如何在nodejs中保持速度调用10000行的大数据

Javascript 不上传二进制数据

javascript - 是否有其他方法可以在 javascript 中引用 grandParent 对象

linux - 如何使用 Linux 将 VBS 脚本转换为 .EXE?