[英]javascript function does not work
我目前正在开发一个网站。 如果用户按下按钮,则需要调用javascript函数。 我将此功能简化为:
<html>
<head>
<script type="text/javascript">
function newProd(number,customer,software,hardware,name)
{
//I simplified this function
alert('number is: '+number+'customer is: '+customer+' software is: '+software+' hardware is: '+hardware+' name is: '+name);
}
</script>
</head>
<body>
<input type="text" name="textfieldCustomer"><br>
<input type="text" name="textfieldSoftware"><br>
<input type="text" name="textfieldHardware"><br>
<input type="text" name="textfieldDescription"><br>
<input type="button" name="button" value="go to function" onClick="newProd('a number',textfieldCustomer.value,textfieldSoftware.value,textfieldHardware.value,textfieldDescription.value)">
</body>
当用户按下Internet Explorer中的按钮时,该功能将完美运行! 不幸的是,该功能在Chrome或Safari中不起作用。
有谁知道出什么问题了吗?
不应将表单字段定义为全局变量。 也许在IE中是,但这不是您可以依赖的行为。 尝试这个:
onClick="newProd('a number',
this.form.textfieldCustomer.value,
this.form.textfieldSoftware.value,
this.form.textfieldHardware.value,
this.form.textfieldDescription.value)">
哦,然后添加一个表格来包装输入内容。
演示: http : //jsfiddle.net/kdUMc/
在我看来,您的代码有两个大错误。 首先,对输入字段的访问是错误的。 它需要与实例变量(例如“ document”)的连接。 第二个,表单标记丢失。 如果将输入字段包装到表单标签中,则可以访问Esailija发布的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.