繁体   English   中英

JavaScript函数href

[英]JavaScript function href

我正在用onclick激活的javascript中创建一个函数,我只需要简单的javascipt代码行即可链接到另一个html页面。

<area shape="rect" coords="78,348,182,395" onclick="nextquestion">

用户点击该区域

function nextquestion(){
   window.location="contact.html";
}

链接到此功能

为什么不使用<area .... href="" /> Href对区域标签有效

您未在以下代码中执行该函数:

<area shape="rect" coords="78,348,182,395" onclick="nextquestion">

nextquestion仅作为指向该函数的未使用变量而保留在那里。

使用nextquestion()实际执行功能:

<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">

您需要更改onclick来调用该函数,在JS中,这需要在函数名称后加上一组括号,例如:

<area shape="rect" coords="78,348,182,395" onclick="nextquestion();">

然后在你的JS里

function nextquestion() {
    window.location.href = 'contact.html';
}

你尝试过这个吗?

<area shape="rect" coords="78,348,182,395" href = 'contact.html'>

要么

<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">

暂无
暂无

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

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