Html按钮不显示表单

时间:2017-05-03 05:08:31

标签: javascript html

这是我的代码。我创建了一个按钮,在点击事件中我想显示表单,但我的表单没有显示。

  

发出错误"未捕获的SyntaxError:无效或意外的令牌"



<input id="Result" name="display" type="button" value="Cost Report" onclick=  document.getElementById("form id").style.display="block";
      style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">
    
    <div> 
        <form id="form id" style="display: block;">Results</form>
    </div>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:2)

将事件绑定到元素时,它们应由"'包装。

&#13;
&#13;
<input id="Result" name="display" type="button" value="Cost Report" onclick='document.getElementById("form id").style.display="block";' style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">

<div>
  <form id="form id" style="display: none;">Results</form>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个。你应该添加单引号--MENU-- Dim login As New LoginClass login.ShowDialog() --CONEXION-- Private conec As SqlConnection Dim stringCon As String = "Data Source= ;Initial Catalog=;Persist Security Info=True;User ID=;Password=" Public ReadOnly Property prConec() As Object Get Return conec End Get End Property Public Sub Conectar() Try conec = New SqlConnection(stringCon) If conec.State <> ConnectionState.Open Then conec.Open() End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub --BUSCAR-- funciones.Conectar() Dim coman As New SqlCommand("sp_cliente", funciones.prConec) Dim dt As New DataTable coman.CommandType = CommandType.StoredProcedure coman.Parameters.Add("@i_operacion", SqlDbType.Char, 1, ParameterDirection.Input).Value = "B" dt.Load(coman.ExecuteReader()) grdClientes.DataSource = dt --INSERTAR-- funciones.Conectar() Dim coman As New SqlCommand("sp_articulo", funciones.prConec) coman.CommandType = CommandType.StoredProcedure coman.Parameters.Add("@i_operacion", SqlDbType.Char, 1, ParameterDirection.Input).Value = "I" coman.ExecuteNonQuery() Buscar() Limpiar() --COMBO-- Dim dt As New DataTable dt.Columns.Add("Codigo") dt.Columns.Add("Descripcion") Dim dr1 As DataRow = dt.NewRow dr1.Item("Codigo") = "A" dr1.Item("Descripcion") = "Activo" dt.Rows.Add(dr1) Dim dr2 As DataRow = dt.NewRow dr2.Item("Codigo") = "I" dr2.Item("Descripcion") = "Inactivo" dt.Rows.Add(dr2) cmbEstado.DataSource = dt cmbEstado.ValueMember = "Codigo" cmbEstado.DisplayMember = "Descripcion" --GRIDVIEW-- --1-- Dim grdFila As DataGridViewRow = grdClientes.CurrentRow txtCedula.Text = grdFila.Cells(0).Value --2-- If DataGridProductos.CurrentCell.ColumnIndex = 0 Then Dim FLstArticulos As New FLstArticulos FLstArticulos.ShowDialog() DataGridProductos.CurrentRow.Cells(0).Value = FLstArticulos.PrIdArticulo End If --GRIDVIEW.CELLENDEDIT-- If DataGridProductos.CurrentCell.ColumnIndex = 3 Then Dim precio As New Double Dim cantidad As New Double precio = CDbl(grdRow.Cells(2).Value) cantidad = CDbl(grdRow.Cells(3).Value) DataGridProductos.CurrentRow.Cells(4).Value = PLTotalFilaItem(cantidad, precio) PLCargaTotales() End If Sub PLCargaTotales() Dim subTotal As Double Dim iva As Double For Each grd As DataGridViewRow In DataGridProductos.Rows If Not String.IsNullOrEmpty(grd.Cells(4).Value) Then subTotal = subTotal + CDbl(grd.Cells(4).Value) End If Next grd txtSubtotal.Text = subTotal.ToString iva = Decimal.Round(subTotal * 0.12) txtIva.Text = iva.ToString txtTotalPagar.Text = (subTotal + iva).ToString End Sub

onclick='document.getElementById("form id").style.display="block";'

fiddlelink

答案 2 :(得分:0)

id中不应该有任何空格,因为DOM元素的id是唯一的。因此,请将您的表单ID更改为 id =&#34; form-id&#34;

同时设置表格 display:none

  <input id="Result" name="display" type="button" value="Cost Report" onclick='document.getElementById("form-id").style.display="block";'
  style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">

<div> <form id="form-id" style="display: none;">Results</form></div>

答案 3 :(得分:0)

您可以使用ng-show并在点击时显示您的表单,反之亦然

<input id="Result" name="display" type="button" value="Cost Report" onclick= "showForm=!showForm"
      style="overflow:hidden;padding: 5px 5px; border-radius: 3px;font-size: 8.5pt; width:200px ; background-color: #E7FCCA; font-weight: bold; ">

    <div> 
    <form id="form id" ng-show="showForm">Results</form>
</div>