简体   繁体   English

如何将第二个参数传递给javascript函数

[英]How to pass a second argument to a javascript function

I'm working on a jsp containing a javascript function : 我正在处理一个包含javascript函数的jsp:

function validerSelection(identifiant, page) {
   var form = ObjectId("profilForm");
   form.elements['checkedLogin'].value = "" + identifiant;
   form.elements['pageListe'].value = "" + page;
   form.method.value = '<bean:message key="button.valid"/>';
   window.location = "/STFPresentation/admin/profilUtilisateurSearch.do?method="
        + form.method.value + "&nom=" + identifiant + "&page=" + page;
}

The function worked well but I wanted to add a second parameter (called page). 该函数运行良好,但我想添加第二个参数(称为页面)。 "page" is also a variable of my jsp. “页面”也是我的jsp的变量。

I'm calling the javascript function by clicking on a link like this : 我通过单击这样的链接来调用javascript函数:

<a href="javascript:validerSelection('<core:out value="${item.nom}"/>', '<%=numero_page%>')"><core:out value="${item.nom}" /></a>

But nothing happens then. 但是那时什么也没有发生。 Where is my mistake ? 我的错误在哪里?

Many thanks 非常感谢

You may need to add some escapes: 您可能需要添加一些转义符:

try this: 尝试这个:

<a href="javascript:validerSelection('<core:out value=\'${item.nom}\'/>', '<%=numero_page%>')"><core:out value="${item.nom}" /></a>

without using escapes, you're creating a wrong sequence of open/close quotes 如果不使用转义符,则会创建错误的开/关引号序列

I finnaly fixed the problem by adding a hidden value containing my page number 我最终通过添加包含我的页码的隐藏值解决了该问题

Many thanks for your help 非常感谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM