简体   繁体   English

为什么我不能使用 onclick 事件执行这个简单的 JavaScript 函数?

[英]Why I can't perform this simple JavaScript function using the onclick event?

I am not so into JavaScript and I have the following problem.我不太喜欢 JavaScript,我有以下问题。

Into a JSP page I have the following "link":进入 JSP 页面,我有以下“链接”:

<tr onmouseout="Javascript: this.style.background='#FFFFFF'; 
                            this.style.color='#003399';" 
                            onmouseover="Javascript: this.style.background='#003399'; 
                            this.style.color='#FFFFFF'; this.style.cursor='hand';" 
                            onclick="changeLocationTo('edi.do?serv=4.U');">

    <td style="border-top: 0px;">
        Tabella Anagrafica
    </td>
</tr>

So, when the user click on the tr element it is performed the changeLocationTo() JavaScript function passing to it the String 'edi.do?serv=4.U' .因此,当用户单击tr元素时,它会执行changeLocationTo() JavaScript 函数,并将字符串'edi.do?serv=4.U'传递给它。

Into this page I have defined the script section:在此页面中,我定义了脚本部分:

<script language="JavaScript" src="js/Script.js">
    function changeLocationTo(newLocation) {

        alert("INTO changeLocationTo, nweLocation: " + newLocation);
        loadingPopUp();

        // you may add an timeout here or to handle a popup action like closing it

        document.location.href = newLocation;
    }
</script>

My problem is that when I click on the previous tr link it don't perform the changeLocationTo() function and into the FireBug console is is shown this error message every time that I click on the tr :我的问题是,当我单击上一个tr链接时,它不执行changeLocationTo()函数,并且每次单击tr时, FireBug控制台都会显示此错误消息:

ReferenceError: changeLocationTo is not defined参考错误:未定义 changeLocationTo

Why?为什么? what could be the problem?可能是什么问题呢? How can I try to fix it?我该如何尝试修复它? What am I missing?我错过了什么?

您的script元素有一个src属性,因此其中的代码将被忽略,而是加载来自 URL 的脚本。

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

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