使用struts2超链接标签调用javascript函数

calling javascript function using struts 2 hyperlink tag?

本文关键字:javascript 函数 调用 标签 struts2 超链接 使用      更新时间:2023-09-26

我有下面的代码片段在我的jsp,但它不调用addCustomer函数。

 <s:a href="javascript:addCustomer()">Add Customer</s:a>

我错过了什么在使用s:a标签?

与s:a标签对应的html代码为

<a href="javascript:addCustomer();" tabindex="-1">Add Customer</a>

虽然当我使用下面的代码片段javascript函数得到执行。我没有得到什么问题在使用s:a标签?

<a href="#" onclick = "addCustomer();">Add Custome</a>

try this.

<a href="#" onclick = "myfunction(12);">Click</a>

javascript函数

function myfunction(var1)
        {
                var params =var1; //values for passing to struts if any
                var resultStringX = $.ajax({
                type: "POST",
                url:"mystruts2action.action", // struts2 action call
                data: params,
                async: false
                }).responseText;
                resultStringX=$.trim(resultStringX);  // the returning result will be stored in resultStringX variable
        }

试试这三个…

1。

<s:url value="http://www.mkking.com" var="mkyongURL" />
<s:a href="%{mkyongURL}">J2EE web development tutorials</s:a>

2。

<s:a href="http://www.google.com">Google search engine</s:a>

3。

<s:url action="aTagaAction.action" var="aURL" />
<s:a href="%{aURL}">aTagAction</s:a>