-6ren">
gpt4 book ai didi

javascript - 如何在jsp页面中获取表达式标签的值到javascript进行验证?

转载 作者:行者123 更新时间:2023-11-30 18:32:52 25 4
gpt4 key购买 nike

<table>
<tr>
<td>&nbsp;</td>
<td>
<a id=<%= id%> href="javascript:redirect()" >
<img src=<%= s%> style="width:90px; height:90px;" />
</a>
</td>
<td>
<p>Product Name : <%= name %></p>
<p>Product Price : <%= list.get(i).getProdPrice() %></p>
</td>
</tr>
</table>

我需要获取 <%= id%> 的值在 jsp 代码中 [ <a id=<%= id%> href="javascript:redirect()" > ] 在我的 javascript 中。我正在调用 javascript redirect() ,

如何获取 id 的值在我的javascript中?这是我的 javascript。

function redirect(){
var a = document.getElementById("id").value;
alert(a);
}

我需要在 javascript 函数中获取值并需要从 javascript 提交页面。

我正在使用 struts2 框架。

最佳答案

如果我正确理解问题,您需要将值 <%= id%> 传递给您的 javascript 函数。您可以通过对代码进行以下更改来做到这一点

将 javascript 函数更改为:

 function redirect(id){
alert(id); /* or any other processing you need */
}

并在 JSP 中附加重定向 as

<table>
<tr>
<td>&nbsp;</td>
<td>
<a href="javascript:redirect(<%= id%>)" >
<%-- CHANGE MADE ABOVE -- %>

<img src=<%= s%> style="width:90px; height:90px;" />
</a>
</td>
<td>
<p>Product Name : <%= name %></p>
<p>Product Price : <%= list.get(i).getProdPrice() %></p>
</td>
</tr>
</table>

关于javascript - 如何在jsp页面中获取表达式标签的值到javascript进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9107683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com