简体   繁体   English

Struts操作应作为href链接的弹出onclick打开

[英]Struts action should be open as popup onclick of a href link

I have a form on my jsp, 我在jsp上有一个表格,

<form  action="test1_action" name="test" method="post" id="test">

also I have two different link link1 , link2 here, 我也有两个不同的链接link1link2在这里,

onclick of link1 I should submit test1_action action link1的onclick我应该提交test1_action操作

$('#link1').click(function() {  
        document.forms['test'].action='test1_action';
        document.forms['test'].submit();
}); 

This works perfect for me. 这对我来说很完美。

what My expectation is when I click the second link popup should open with different action something like follows below. 我的期望是,当我单击第二个链接弹出窗口时,应该使用不同的操作打开,如下所示。

$('#link2').click(function() {
        document.forms['test'].action='**different_action**';
        document.forms['test'].submit();
});

You are using jQuery so there is no need for manual DOM traversal: 您正在使用jQuery,因此无需手动进行DOM遍历:

$('#link1').click(function() {  
  $('#test').attr('action', 'test1_action').submit();
}); 

$('#link2').click(function() {  
  $('#test').attr('action', 'test2_action').submit();
}); 

The action attribute defines the page to which the form sends its contents, most commonly a page that interfaces with the server in some way (PHP, JSP, etc.). action属性定义表单将其内容发送到的页面,最常见的是以某种方式(PHP,JSP等)与服务器连接的页面。

What do you mean by "popup"? “弹出”是什么意思?

You can use window.open() to open a window with a specific name, and then use that name as the target for the form submit. 您可以使用window.open()打开具有特定名称的窗口,然后将该名称用作表单提交的目标。

$('#link2').click(function() {
   window.open("","test2win","directories=no,status=no,width=600,height=700,top=0,left=0");

   $('#test').attr({
     'action' : 'test2_action',
     'target' : 'test2win'
   }).submit();
});

I'm not sure that the above will work in all browsers though. 我不确定以上内容是否能在所有浏览器中正常工作。 If not, you might have to just forget the window.open() step and just submit the form with target=_blank and then set the size from within the page being returned from the submit. 如果不是,您可能只需要忘记window.open()步骤,只需使用target=_blank提交表单,然后从提交返回的页面中设置大小即可。

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

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