如何在 JSP 中的“单击”复选框时创建删除按钮
how to create a delete button when onclick checkbox in jsp?
我想在单击复选框时在jsp页面上显示或插入一个按钮。这是我的代码。它不起作用。这是我的索引.jsp页面谁能帮我??
JSP 页面
function validateForm()
{ var validfirstUsername = document.form.text1.value.match(/^[A-Za-z ]{3,20}$/);
var validage=document.form.text2.value.match(/^[1-9]?[0-9]{1}$|100/);
var validphoneno = document.form.text3.value.match(/^'d{10}$/);
if(validfirstUsername == null){
alert("Your first name is not valid");
document.form.text1.value = "";
return false;
}
if(validage ==null){
alert("Your age is not valid");
document.form.text2.value = "";
return false;
}
if( validphoneno==null){
alert("Your phone no is not valid");
document.form.text3.value = "";
return false;
}
}
</script>
</head>
<body style= "background-image: url(index.jpeg);background-repeat:no-repeat;" >
<div id="new">
<%!
Connection con;
PreparedStatement ps;
ResultSet rs;
String q;
%>
<% try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/jspdatabase","root", "kca@fnpl#12");
Statement st=con.createStatement();
}catch(Exception e){}%>
<h1>Enter student details....</h1>
<%! public void checkid(String a){%>
<input type="submit" value="Delete" name="delete" />
<%! }%>
<form name="form" action="submit.jsp"method="post" onsubmit="return validateForm()" method="post">
<center> Name: <input type="text" name="text1" value="" /><br><br>
Age :    <input type="text" name="text2" value="" /><BR><br>
Sex :    male<input type="radio" name="bg" value="male"/>
female<input type="radio" name="bg" value="female" /><BR><br>
phone no:<input type="text" name="text3" value="" /><BR><br>
Date:<select name="date">
<% for(int i=1;i<32;i++){%>
<option><%=i%></option>
<%}%>
</select>
<select name="month">
<% for(int i=1;i<13;i++){%>
<option><%=i%></option>
<%}%>
</select>
<select name="year">
<% for(int i=1990;i<1996;i++){%>
<option><%=i%></option>
<%}%>
</select><br><br>
<input type="submit" value="submit" name="submit" />
</form>
<%
q="select id,name,age,sex,phone,date,mark1,mark2 from table1";
try{
ps = con.prepareStatement(q);
rs = ps.executeQuery();
}
catch(Exception e){
}%>
<table border="1">
<thead>
<tr>
<th>selection</th>
<th>id</th>
<th>name</th>
<th>age</th>
<th>sex</th>
<th>phone</th>
<th>date_of_birth</th>
<th>mark1</th>
<th>mark2</th>
</tr>
</thead>
<tbody>
<%
while(rs.next())
{
%>
<tr>
<td><input type="checkbox" name="check" value="off" onClick="checkid(<%=rs.getString(1) %>);"/></td>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
<td><%=rs.getString(8)%></td>
</tr>
<%}
%>
</tbody>
</table>
</center>
</form>
</body>
</div>
</html>
谢谢...
你的checkid
函数在<%
标签下并在服务器端运行,同时onclick=
将只执行javascript,即客户端。
创建客户端函数checkid
:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function checkid(id) {
$('#delete_button').show();
}
</script>
<input type="button" id="delete_button" style="display: none" value="Delete"/>
单击复选框时
$(document).ready(function(){
$('input[type="checkbox"]').bind('click',function()
{
alert($(this).is(":checked"));
//Or you could use alert($(this).attr("checked") == "checked");
});
});
基于检查写入功能
相关文章:
- 如何创建php函数或任何脚本/jquery Javascript,使我能够获取与复选框关联的值并添加它们
- 动态创建唯一的复选框
- 如何创建只允许用户在选中前一个复选框的情况下选择复选框的复选框验证
- 如何在 Angular JS 中从关联数组创建多个复选框
- 单击或取消选中复选框时,如何创建弹出的自定义窗口
- 基于所选下拉列表值创建动态复选框
- “动态创建的表”上的复选框(每行最多只能选择1个)
- 函数更改不适用于动态创建的表的复选框
- 如何创建一个新的<李>带有复选框或<a>在里面
- 在react中切换动态创建的复选框
- 在服务器上创建一个复选框,使用 javascript 处理函数
- jQuery .change() 方法不适用于动态创建的复选框
- 如何创建至少 1 个框处于活动状态的复选框列表
- 为选中的每个复选框创建隐藏输入
- 从复选框创建具有复杂变量的对象
- JavaScript 从表单元素处理复选框创建 URL
- 动态复选框创建以在单击时运行函数
- 如何使用输入复选框创建/更新数组
- Joomla-使用ajax从复选框创建会话变量
- 无法使用 jquery AJAX PHP 为复选框创建数组