使用Javascript无效的广播验证

时间:2017-09-14 20:03:42

标签: javascript

我有一些HTML和Javascript代码。每当我测试它时,我得到一个错误,我的函数没有定义。我不知道为什么会这样。我已经检查了代码,但我没有看到任何与它有关的错误。

function proccessSecurity(el) {
	if (el.value == "none") {
		document.getElementById('tid-password').style = "display: none;";
		document.getElementById('tid-users-allowed').style = "display: none;";
	}

	if (el.value == "password") {
		document.getElementById('tid-password').style = "display: block;";
		document.getElementById('tid-users-allowed').style = "display: none;";
	}

	if (el.value == "specific") {
		document.getElementById('tid-password').style = "display: none;";
		document.getElementById('tid-users-allowed').style = "display: block;";
	}

}
<textarea rows="20" cols="100" id="tid-text-area"></textarea><br><br>

Security<br>
<input onchange="processSecurity(this);" type="radio" name="security" value="none" checked> No security.</input><br>
<input onchange="processSecurity(this);" type="radio" name="security" value="password"> Allow only users with a password.</input><br>
<input onchange="processSecurity(this);" type="radio" name="security" value="specific"> Allow only specified users.</input><br>
<input style="display: none;" type="password" id="tid-password"><br><br>
<input style="display: none;" type="text" id="tid-users-allowed"><br><br>

3 个答案:

答案 0 :(得分:2)

您的内联处理程序为processSecurity,但您的函数定义为proccessSecurity。简单的错字。

答案 1 :(得分:2)

您应该更改代码中的拼写错误

<强> proccessSecurity

<强> processSecurity

并且它不会显示未定义的功能

答案 2 :(得分:0)

unit UThreadDB;

interface 

uses Classes, DBClient, DB, SysUtils, Variants, JvJCLUtils;

type

  TParametros = class
  private
    FTotal: Integer;
    FCampo: array of string;
    FTipo: array of TFieldType;
    FValor: array of Variant;
  public
    constructor Create(ACampos: string; ATipos: array of TFieldType; AValores: array of Variant); reintroduce;
  end;

  TThreadDB = class(TThread)
  private
    FExecutou: Boolean;
    FClientDataSet: TClientDataSet;
    FConsultaSQL: string;
    FParametros: TParametros;
    procedure CarregarDados;
  protected
    procedure Execute; override;
  public
    constructor Create(ACreateSuspended: Boolean; AClientDataSet: TClientDataSet; AConsultaSQL: string = '';
      AParametros: TParametros = nil); reintroduce;

    class function ExecutarThreadDB(AClientDataSet: TClientDataSet; AConsultaSQL: string = '';
      AParametros: TParametros = nil; APriority: TThreadPriority = tpNormal): Boolean;

    class procedure ExecutarThreadDBParalela(AThreadDB: TThreadDB; AClientDataSet: TClientDataSet;
      AConsultaSQL: string = ''; AParametros: TParametros = nil; APriority: TThreadPriority = tpNormal);
  end;

implementation

uses
   BIBLIO;

{ TThreadDB }

class function TThreadDB.ExecutarThreadDB(AClientDataSet: TClientDataSet; AConsultaSQL: string = '';
   AParametros: TParametros = nil; APriority: TThreadPriority = tpNormal): Boolean;
var
   lThreadDB: TThreadDB;
begin
   lThreadDB := TThreadDB.Create(True, AClientDataSet, AConsultaSQL, AParametros);

   try

      //lThreadDB.FreeOnTerminate := True;
      lThreadDB.Priority := APriority;
      lThreadDB.Resume;

      lThreadDB.WaitFor;

      Result := lThreadDB.FExecutou;

   finally
      lThreadDB.Terminate;

      //lThreadDB := nil;
      FreeAndNil(lThreadDB);
   end;
end;

class procedure TThreadDB.ExecutarThreadDBParalela(AThreadDB: TThreadDB; AClientDataSet: TClientDataSet;
   AConsultaSQL: string = ''; AParametros: TParametros = nil; APriority: TThreadPriority = tpNormal);
begin
   AThreadDB := TThreadDB.Create(True, AClientDataSet, AConsultaSQL, AParametros);

   AThreadDB.FreeOnTerminate := True;
   AThreadDB.Priority := APriority;
   AThreadDB.Resume;
end;

procedure TThreadDB.CarregarDados;
var
   lIndex: Integer;
begin
   FClientDataSet.Close;

   try

      if (FConsultaSQL <> '') then
      begin
         FClientDataSet.CommandText := FConsultaSQL;
      end;

      if (FParametros <> nil) then
      begin
         for lIndex := 0 to (FParametros.FTotal - 1) do
         begin
            case FParametros.FTipo[lIndex] of
               ftInteger : FClientDataSet.Params.ParamByName(FParametros.FCampo[lindex]).AsInteger := FParametros.FValor[lIndex];
               ftString  : FClientDataSet.Params.ParamByName(FParametros.FCampo[lindex]).AsString  := FParametros.FValor[lIndex];
               ftDate    : FClientDataSet.Params.ParamByName(FParametros.FCampo[lindex]).AsDate    := FParametros.FValor[lIndex];
            end;
         end;
      end;

      FClientDataSet.Open;

      FExecutou := True;

   except
      on E: Exception do
      begin
        Erro('Não foi possível carregar os dados solicitados!' + #13 +
             'Classe do erro: ' + E.ClassName + #13 +
             'Mensagem: ' + E.Message);
      end;
   end;

   if (FParametros <> nil) then
   begin
      FreeAndNil(FParametros);
   end;
end;

constructor TThreadDB.Create(ACreateSuspended: Boolean; AClientDataSet: TClientDataSet; AConsultaSQL: string = '';
   AParametros: TParametros = nil);
begin
  inherited Create(ACreateSuspended);

   FClientDataSet := AClientDataSet;

   FConsultaSQL := AConsultaSQL;

   FParametros := AParametros;

   FExecutou := False;
end;

procedure TThreadDB.Execute;
begin
   CarregarDados;
end;

{ TParametros }

constructor TParametros.Create(ACampos: string; ATipos: array of TFieldType; AValores: array of Variant);
var
   lIndex: Integer;
begin
  inherited Create;

   FTotal := ContaCaracteres(ACampos, ';') + 1;

   SetLength(FCampo, FTotal);
   SetLength(FTipo, FTotal);
   SetLength(FValor, FTotal);

   for lIndex := 0 to FTotal - 1 do
   begin
      FCampo[lIndex] := ExtractDelimited(lIndex + 1, ACampos , [';']);
   end;

   for lIndex := 0 to FTotal - 1 do
   begin
      FTipo[lIndex] := ATipos[lIndex];
   end;

   for lIndex := 0 to FTotal - 1 do
   begin
      FValor[lIndex] := AValores[lIndex];
   end;
end;

end.
function proccessSecurity(el) {
	if (el.value == "none") {
		document.getElementById('tid-password').style = "display: none;";
		document.getElementById('tid-users-allowed').style = "display: none;";
	}

	if (el.value == "password") {
		document.getElementById('tid-password').style = "display: block;";
		document.getElementById('tid-users-allowed').style = "display: none;";
	}

	if (el.value == "specific") {
		document.getElementById('tid-password').style = "display: none;";
		document.getElementById('tid-users-allowed').style = "display: block;";
	}

}

<textarea rows="20" cols="100" id="tid-text-area"></textarea><br><br> Security<br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="none" checked> No security.</input><br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="password"> Allow only users with a password.</input><br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="specific"> Allow only specified users.</input><br> <input style="display: none;" type="password" id="tid-password"><br><br> <input style="display: none;" type="text" id="tid-users-allowed"><br><br> =&gt; <input onchange="processSecurity(this);"

你错过了'c'过程。