<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
/jquery/1.4.0/jquery.min.js"></script>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
</head>
<body>
This is my JSP page. <br>
<s:form id="loginForm">
<s:textfield name="user" label="用户名"/>
<s:textfield name="pass" label="密码"/>
<tr><td colspan="2">
<input id="loginBn" type="button" value="提交"/>
</td></tr>
</s:form>
<div id="show" style="display:none;">
</div>
<script type="text/javascript">
$("#loginBn").onclick=function(){
var value=document.getElementById("loginBn").value
alert(value)
//alert($("#loginBn"))
}</script>
</body>
</html>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs
/jquery/1.4.0/jquery.min.js"></script>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
</head>
<body>
This is my JSP page. <br>
<s:form id="loginForm">
<s:textfield name="user" label="用户名"/>
<s:textfield name="pass" label="密码"/>
<tr><td colspan="2">
<input id="loginBn" type="button" value="提交"/>
</td></tr>
</s:form>
<div id="show" style="display:none;">
</div>
<script type="text/javascript">
$("#loginBn").onclick=function(){
var value=document.getElementById("loginBn").value
alert(value)
//alert($("#loginBn"))
}</script>
</body>
</html>
$("#loginBn").click(function(){
var value=document.getElementById("loginBn").value
alert(value)
//alert($("#loginBn"))
});
<script type="text/javascript">
$(document).ready(function(){
//你的代码
$("#loginBn").click(function(){
var value=document.getElementById("loginBn").value
alert(value)
//alert($("#loginBn"))
});
});
</script>
这样写?怎么还是弹不出来
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$("#loginBn").click(function(){
var value=("#loginBn").attr("value");
alert(value);
});
})
</script>
$("#loginBn")[0].onclick(function(){
var value=("#loginBn").attr("value");
alert(value);
});jquery选择器得到是一个数组不是一个元素,给数组绑定事件显然和你的预期不一致
$("#loginBn")[0].onclick(function(){
var value=document.getElementById("loginBn").value;
alert(value);
});
$("#loginBn")[0].onclick = function(){
var value=document.getElementById("loginBn").value;
alert(value);
};
我发现拷别人的不靠谱
<script type="text/javascript">
$(document).ready(function(){
$("#loginBn").click(function() {
var value = $("#loginBn").val();
alert(value)
});
})
</script>这样写肯定没有问题的,如果还是不出效果的话那只有一个可能:没有引用jquery文件 或者引用的文件路径不对,lz找找其它地方吧
//你的代码
});
为啥一定要写到这里呢,不写到里面一定注册不上吗?
var value=document.getElementById("loginBn").value解释一下为什么引入jQuery后还用document.getElementById……
呵呵,惯用dom,初学jQuery,用着不顺手!