我试图通过点击jsp表单中的按钮来获取按钮值。但出于某种原因,当我点击按钮时,它总是显示“1”。那么,我可能做错了什么?我还在学习Javascript,当我点击它时,我实现了一个小脚本来显示按钮值。我觉得我的Javascript代码出错了。请帮帮我。
JSP页面: -
df = df.astype(int)
(df / df.sum()).groupby(level=0).sum() * 100
JSP页面的完整代码
<table
<tr>
<td colspan=4 align="center"
style="background-color:teal">
<b>User Record</b></td>
</tr>
<tr style="background-color:lightgrey;">
<td><b>Record Number: </b></td>
<td><b>Card Number: </b></td>
<td><b>MiddleName:</b></td>
<td><b>BankAccountID:</b></td>
<td><b>CurrencyID:</b></td>
<td><b>DayTransactionLimit:</b></td>
<td><b>Select:</b></td>
</tr>
<%
if(request.getParameter("mobilenumber")!=null)
{
FileReader fr = new FileReader(new File(("C:\\Users\\Surajitdas\\Documents\\NetBeansProjects\\Demo\\records.txt")));
BufferedReader br = new BufferedReader(fr);
String line = null;
int count =0;
// out.println("<table>");
while((line = br.readLine()) != null){
//out.print(line + "<br/>");
out.println("<tr>");
count ++;
String[] data = line.split("\t");
for (String val : data) {
out.println("<td>" + val + "</td>");
}
out.println("<td><input type =\"button\" id=\"getid\" onclick=\"getbuttonid()\" value=\"" + count + "\"></td>");
}
out.println("");
br.close();
}
%>
</table>
</table
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
function getbuttonid(){
var id = document.getElementById('getid').value;
alert(id);
}
</script>
答案 0 :(得分:0)
您的注意事项:1)ID仅适用于html标记中的单个元素(您的按钮都具有相同的ID“getid”且不应该这样做),如果要分配单个名称,请使用class将字符串定位到多个元素
2)你可以在html标记中使用 this 来定位分配函数的元素,检查我更新的代码以完全理解我的喋喋不休
private DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("user_details").child("user_id").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = null, surname = null, email = null, phone = null, bd = null, gender = null;
for (DataSnapshot child : dataSnapshot.getChildren()) {
if (child.getKey().equals("firstName")) {
name = child.getValue().toString();
}
if (child.getKey().equals("lastName")) {
surname = child.getValue().toString();
}
if (child.getKey().equals("birthday")) {
bd = child.getValue().toString();
}
if (child.getKey().equals("email")) {
email = child.getValue().toString();
}
if (child.getKey().equals("gender")) {
gender = child.getValue().toString();
}
if (child.getKey().equals("phone")) {
phone = child.getValue().toString();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});