我有這個按鈕:的OnClientClick不工作
<asp:Button runat="server" ID="botao" OnClientClick="submit();" OnClick="submeter" Text="Pedir Revisão" />
這個JavaScript函數:
function submit() {
alert("entrei");
//tabelaAutores
var tabela = document.getElementById("tabelaAutores");
var tableAux = document.getElementById('<%=tabelaAutoresAux.ClientID %>');
var x = tabela.rows.length;
for (i = 1; i < x; i++) {
tableAux.innerText += tabela.rows[i].cells[0].innerText + "/" + tabela.rows[i].cells[1].innerText + "|";
}
alert(tableAux.innerText);
return false;
}
這個C#函數:
protected void submeter(object sender, EventArgs e)
{
Debug.WriteLine("aqui----");
Debug.Write(tabelaAutoresAux.InnerText);
int id = int.Parse(Request.QueryString["id"]);
//adicionar autores
String[] aC = tabelaAutoresAux.InnerText.Split('|');
for (int i = 0; i < aC.Length - 1; i++)
{
String[] aC2 = aC[i].Split('/');
DataTable pessoa = DBConFactory.getInstance().getPessoaByEmail(aC2[1]);
if (pessoa.Rows.Count != 0)
{
bool x = DBConFactory.getInstance().add(int.Parse(pessoa.Rows[0]["nOrdem"].ToString()), id);
}
}
}
的代碼在C#中的功能進入,但不在JavaScript代碼中。
這是整個代碼。
<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AdicionarRevisor.aspx.cs" Inherits="CasosClinicos.Admin.AdicionarRevisor" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script>
var PopupImageContainer = new Image();
var PopupImageCaption = new String();
var PopupImageSRC = new String();
function PopImage(imagesrc, caption) {
if (length.imagesrc < 1) { return; }
var loadDelay = PopupImageSRC.length ? 1 : 750;
PopupImageSRC = imagesrc;
PopupImageCaption = caption ? caption : 'Image';
PopupImageContainer.src = PopupImageSRC;
setTimeout("PopupImageDisplay()", loadDelay);
}
function PopupImageDisplay() {
var iw = $(window).width() - 50;
var ih = $(window).height() - 50;
var ww = $(window).width();
var hh = $(window).height();
var properties = 'height=' + hh + ',width=' + ww + ',resizable=yes,location=center';
var picture = window.open('', '', properties);
picture.document.writeln('<html><head>');
picture.document.writeln('<script language="JavaScript"> function CloseMe() { self.close(); } <' + '/script>');
picture.document.write('<' + '/head><body onBlur="CloseMe()"><center>');
picture.document.write('<img id="' + PopupImageSRC + '" src="' + PopupImageSRC + '" width="' + iw + '" height="' + ih + '" border="0">');
picture.document.write('<p>' + PopupImageCaption + '<' + '/p>');
picture.document.writeln('<' + '/center><' + '/body><' + '/html>');
}
</script>
<script>
function addAutorB() {
var select = document.getElementById('<%=listaAutores.ClientID %>').value;
if (select.localeCompare("") == 0) {
return;
}
else if (select.localeCompare("Adicionar Novo") == 0) {
document.getElementById("camposAutor").style.display = "block";
document.getElementById("initial").selected = true;
}
else {
var x = select.split("(");
document.getElementById("autores").value = x[0];
document.getElementById("contato").value = x[1].split(")")[0];
addAutor();
}
document.getElementById("initial").selected = true;
}
function addAutor() {
var table = document.getElementById("tabelaAutores");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerText = document.getElementById("autores").value;
cell2.innerText = document.getElementById("contato").value;
cell3.innerHTML = "<button type=\"button\" onclick=\"return deleteRow(this)\" class=\"btn btn-default\" aria-label=\"Left Align\"><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span></button>";
document.getElementById("autores").value = "";
document.getElementById("contato").value = "";
document.getElementById("camposAutor").style.display = "none";
return false;
}
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("tabelaAutores").deleteRow(i);
return false;
}
function submit() {
alert("entrei");
//tabelaAutores
var tabela = document.getElementById("tabelaAutores");
var tableAux = document.getElementById('<%=tabelaAutoresAux.ClientID %>');
var x = tabela.rows.length;
for (i = 1; i < x; i++) {
tableAux.innerText += tabela.rows[i].cells[0].innerText + "/" + tabela.rows[i].cells[1].innerText + "|";
}
alert(tableAux.innerText);
return false;
}
</script>
<br />
<br />
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Revisores</strong></h3>
</div>
<div class="panel-body">
<div class="form-group">
<label for="autores">Revisores</label>
<select runat="server" id="listaRevisores" onchange="addAutorB()">
<option id="initial"></option>
</select>
<br />
<label for="autores">Autores</label>
<select runat="server" id="listaAutores" onchange="addAutorB()">
<option id="initial1"></option>
</select>
<style>
table.fixed {
table-layout: fixed;
}
table.fixed td {
overflow: hidden;
}
</style>
<div id="camposAutor" style="display: none;">
<input type="text" id="autores">
<input type="text" id="contato" />
<button type="button" onclick="return addAutor()" class="btn btn-default" aria-label="Left Align\"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</div>
<table id="tabelaAutores" border="1" class="fixed">
<col width="255px" />
<col width="255px" />
<col width="90px" />
<tr>
<td><strong>Autor</strong></td>
<td><strong>Contato</strong></td>
<td></td>
</tr>
</table>
<br />
</div>
<div id="autoresAux" runat="server" style="display: none;">
<textarea runat="server" id="tabelaAutoresAux"></textarea>
</div>
<div>
<asp:Button runat="server" ID="botao" OnClientClick="submit();" OnClick="submeter" Text="Pedir Revisão" />
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default" style="position: fixed; overflow: auto; height: 85%">
<div class="panel-heading">
<h3 class="panel-title"><strong>Caso</strong></h3>
</div>
<div class="panel-body">
<div style="overflow: auto; padding: 5px;">
<div class="form-group">
<label runat="server">Titulo: </label>
<p runat="server" id="text_titulo"></p>
<label runat="server">Autores: </label>
<p runat="server" id="text_autores"></p>
<label runat="server">Intituição: </label>
<p runat="server" id="text_inst"></p>
<label>Resumo: </label>
<pre runat="server" id="text_resumo"></pre>
<div id="conteudo">
<p runat="server" id="text_conteudo"></p>
</div>
<label>Imagens: </label>
<p runat="server" id="text_img"></p>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content>
我已經嘗試了所有種類的東西......與<button onclick="submit">botao</button>
替代按鈕,它不工作。
的嘗試重命名提交(),以其它名稱爲submit1()...我得到了同樣的問題once..when我改變它,它得到了工作的另一個名字.. – Sachu
我只是做到這一點和它的作品......不知道爲什麼。 ..但是沒問題!謝謝!!! – stack01
@ stack01可能有一些其他的函數或變量具有相同的名稱爲'submit'(可能是從一個參考文件或此類) –