gpt4 book ai didi

javascript - HTML 中 Javascript 函数的问题

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:11 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com