Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
915 views
in Technique[技术] by (71.8m points)

javascript - jQuery function error

Here is my piece of code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Shout!</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

var status=1;
function action() {



if(status==1) {
$("#Layer1").hide("slow");
$("#Layer3").hide("fast");
$("#Layer4").hide("slow");
$("#close").attr("src","open.jpg");
status=0;

}

else if(status==0) {
status=1;
$("#Layer1").show("slow");
$("#Layer3").show("fast");
$("#Layer4").show("slow");
$("#close").attr("src","close.jpg");

}




}


function sendline() {

$("#msg").val(" ");

}

function type() {
var text=$("#msg").val();

$("#Layer6").html(text);

}

</script>
<style type="text/css">
<!--
    body {
 background-color: #000000;
    }
    #Layer1 {
 position:absolute;
 width:200px;
 height:115px;
 z-index:1;
 left: 179px;
 top: 3px;
    }
    #Layer2 {
 position:absolute;
 width:69px;
 height:64px;
 z-index:2;
 left: 570px;
 top: 543px;
    }
    #Layer3 {
 position:absolute;
 width:124px;
 height:22px;
 z-index:3;
 left: 473px;
 top: 474px;
    }
    .style1 {
 color: #FFFFFF;
 font-family: "Segoe UI";
 font-weight: bold;
    }
    #Layer4 {
 position:absolute;
 width:72px;
 height:27px;
 z-index:4;
 left: 744px;
 top: 485px;
    }
    #Layer5 {
 position:absolute;
 width:274px;
 height:70px;
 z-index:5;
 left: 422px;
 top: 62px;
    }
    #Layer6 {
 position:absolute;
 width:638px;
 height:356px;
 z-index:5;
 left: 272px;
 top: 105px;
    }
-->
</style></head>

<body>
<div class="style1" id="Layer3">
<textarea id="msg" style="height:50px;width:250px" rows="10" cols="80" onkeyup="type()"></textarea></div>
<div id="Layer1">Hello World!<img src="body.jpg" alt="Shout !" width="842" height="554" /></div>
<div id="Layer2"><img src="close.jpg" id="close" width="63" height="64" OnClick="action()"/></div>
<div id="Layer4">
<input type="button" value="Send Line" onclick="sendline()" /></div>
<div id="Layer6" style="color:#FFFFFF;"></div>
</body>
</html>

I'm facing a problem with the type() function.Its simply not running

Any advice on how to get it rnnning?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your function is running, however it's throwing an error because of the function name:

Uncaught TypeError: string is not a function

or in Firefox:

type is not a function

In short, you can't use type as a function name here, you just need to give it a slightly different name, for exampled typed.

Here's your code only changing the function name, working :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...