javascript方法调用不了,为什么?
<script>functioncitys(name,city){this.name=name;this.city=city;this.show=show;}functi...
<script>
function citys(name,city){
this.name=name;
this.city=city;
this.show=show;
}
function show(){
for(var x in this)
alert(x+=""+this[x]+"");
}
function get(){
var name_one=document.forms.name_one.value;
var city_one=document.forms.city_one.value;
name1=new citys(name_one,city_one);
}
</script>
</head>
<body>
<form name="forms" method="post">
<input type="text" name="name_one" >
<input type="text" name="city_one" >
<input type="button" value="ok" onclick=javascript:get() >
</form>
</body>
show方法调用不了,为什么?
哪里出的问题? 展开
function citys(name,city){
this.name=name;
this.city=city;
this.show=show;
}
function show(){
for(var x in this)
alert(x+=""+this[x]+"");
}
function get(){
var name_one=document.forms.name_one.value;
var city_one=document.forms.city_one.value;
name1=new citys(name_one,city_one);
}
</script>
</head>
<body>
<form name="forms" method="post">
<input type="text" name="name_one" >
<input type="text" name="city_one" >
<input type="button" value="ok" onclick=javascript:get() >
</form>
</body>
show方法调用不了,为什么?
哪里出的问题? 展开
推荐于2016-03-30
展开全部
<!DOCTYPE HTML>
<html>
<head>
<title>学了又学之一根筋重现</title>
<meta charset=UTF-8 />
<style type="text/css">
</style>
<script type="text/javascript">
function citys (name, city)
{
this.name = name;
this.city = city;
}
citys.prototype.toString = function ()
{
return "name = " + this.name + ", city = " + this.city;
}
function get ()
{
var name_one = document.forms.name_one.value;
var city_one = document.forms.city_one.value;
var name1 = new citys (name_one, city_one);
alert (name1.toString ());
return false;
}
</script>
</head>
<body>
<form name="forms" method="post">
<input type="text" name="name_one" >
<input type="text" name="city_one" >
<input type="button" value="ok" onclick="return get()" />
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询