请帮助我不断返回TypeError$(..)为null

Please help I keep getting back a TypeError $(...)is null

本文关键字:null TypeError 返回 帮助      更新时间:2023-09-26

我的老师制作了一个js文件,告诉我们找到错误并修复它们。但是,我陷入了困境。

//this function is called when the user enters invalid data into the form and hits the calculate button
function clearField(field_name) {
//set the value of the passed in field name to blank
$("field_name").value = "";
$("field_name").value = "";   keeps returning an error message like this:

TypeError$(…)为空

对不起,我在事故中用引号做了这件事。我把它重新命名为$(field_name).value == ("");,它起作用了。

由于field_name是函数的参数,因此不应将其括在引号中。

应该是:

$(field_name).value() = ";

编辑

我的坏。它应该是$(field_name).val("");而不是