[英]JavaScript function href
I'm creating a function in javascript
that is activated by an onclick
and I just need a simple line of javascipt
code to link to another html page. 我正在用
onclick
激活的javascript
中创建一个函数,我只需要简单的javascipt
代码行即可链接到另一个html页面。
<area shape="rect" coords="78,348,182,395" onclick="nextquestion">
user clicks on that area 用户点击该区域
function nextquestion(){
window.location="contact.html";
}
links to this function 链接到此功能
Why don't use <area .... href="" />
? 为什么不使用
<area .... href="" />
? Href is valid for area tag Href对区域标签有效
You are not executing the function in this code: 您未在以下代码中执行该函数:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion">
nextquestion
only stays there as a unused variable pointing to the function. nextquestion
仅作为指向该函数的未使用变量而保留在那里。
Use nextquestion()
to actually execute the function: 使用
nextquestion()
实际执行功能:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">
You'd want to change your onclick to call the function, in JS this requires a set of parentheses after the name of the function like: 您需要更改onclick来调用该函数,在JS中,这需要在函数名称后加上一组括号,例如:
<area shape="rect" coords="78,348,182,395" onclick="nextquestion();">
Then in your JS 然后在你的JS里
function nextquestion() {
window.location.href = 'contact.html';
}
did you try this ? 你尝试过这个吗?
<area shape="rect" coords="78,348,182,395" href = 'contact.html'>
or 要么
<area shape="rect" coords="78,348,182,395" onclick="nextquestion()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.