使表现为?

时间:2022-01-24 21:22:30

Inside our web application, we have some messaging functionality for messaging other members. This form is receiving a facelift, and I need to replace some functionality:

在我们的web应用程序中,我们为其他成员提供了一些消息传递功能。这张表格正在接受整容,我需要替换一些功能:

<input type="image" name="cancel" src="/rpc/button/?text=Cancel" />
<input type="image" name="delete" src="/rpc/button/?text=Delete Draft" />
<input type="image" name="send" src="/rpc/button/?text=Send Message" />
<input type="image" name="save" src="/rpc/button/?text=Save Draft" />

I need to change those buttons to use the new CSS buttons we have:

我需要修改这些按钮来使用新的CSS按钮:

<a href="" class="button">Cancel</a>

I have tried doing this, which does submit the form, but it seems as though the name="cancel" is being lost, and the form simply submits without :

我已经试过这样做了,它确实提交了表单,但是似乎name="cancel"正在丢失,表单简单地提交了:

<a class="button" name="cancel" href="javascript:" onclick="$('#frmCompose').submit();">Cancel</a>

Because we are under a deadline, there is no time for rewriting the backend functionality for this.

因为我们已经到了最后期限,所以没有时间为此重写后端功能。

How can I replace these old <input type="image" /> with <a> tags and still pass along a name attribute? I would like to avoid having to create new CSS styles for <button> or <input type="submit" /> if at all possible.

如何将这些旧的替换为标记并继续传递name属性?我希望避免为

7 个解决方案

#1


1  

If adding name="cancel" to your doesn't work, it sounds like you might have to get a little fancy with your javascript. Something like:

如果在你的javascript中添加name="cancel"不起作用,那么你可能需要对你的javascript感兴趣。喜欢的东西:

<input type="hidden" name="placeholder" value="true" />
<a class="button" name="cancel" href="javascript:" onclick="$(this).prev().attr('name', 'cancel'); $('#frmCompose').submit();">Cancel</a>

#2


2  

Uglyish, but use a hidden form field:

但是使用一个隐藏的表单字段:

<input type="hidden" id="clickedname" name="" value="" />

and

<a class="button" name="cancel" href="javascript:" onclick="$('#clickedname').value = this.name; $('#frmCompose').submit();">Cancel</a>
                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^

Adjust the name/value assignments to suit - I can't remember offhand exactly how image inputs submit themselves.

调整名称/值分配以适应——我不记得图像输入是如何自动提交的。

#3


2  

You'll need to use JS to, for example, put a value into a hidden field for the submit, and submit.

您将需要使用JS,例如,将一个值放入隐藏字段中以便提交和提交。

I'd recommend writing a tiny utility function that replaces your onclick attribute value. Better yet, attach the functionality after DOM ready and keep things unobtrusive and localized.

我建议编写一个小的实用函数来替换onclick属性值。更好的是,在DOM就绪后附加功能,保持事物不突兀和本地化。

<a class="button" href="#" onclick="submit('cancel')">Cancel</a>

And submit does what you'd expect, fills the hidden field, and submits the form. If you really can't change the back end at all then you can change the name of the hidden field as well, but ugh; seems like changing the back end to check for an "action" field or something is cleaner.

提交完成您所期望的,填充隐藏字段,并提交表单。如果你真的不能改变后端那么你也可以改变隐藏字段的名字,但是;似乎要更改后端以检查“动作”字段或其他更干净的东西。

#4


1  

Only form elements (<input>, <button>, <textarea>, <select>, etc.) submit values to a form. For an <a> tag to do so, you'd have to use JavaScript to add the value to a form.

只有表单元素(

One way is to add a hidden form element, and set its name/value.

一种方法是添加一个隐藏的表单元素,并设置它的名称/值。

<a class="button" name="cancel" href="#">Cancel</a>
<input type="hidden" id="buttonClicked" />

Then using JavaScript (jQuery):

然后使用JavaScript(jQuery):

$(function(){
    $('a.button').click(function(e){
        e.preventDefault();
        $('#buttonClicked').prop({
            name: $(this).prop('name'),
            value: $(this).prop('name')
        });
        $('#frmCompose').submit();
    });
});

#5


1  

You can add a single hidden field to the form

您可以向窗体添加一个隐藏字段

<input type="hidden" id="action" value=""/>

Then set the value of action in the onclick

然后在onclick中设置动作的值

$("#action").attr("name","---ActionHere---");

So cancel becomes:

所以取消就变成:

<a class="button" href="javascript:" onclick='$("#action").attr("name","cancel");$("#frmCompose").submit();'>Cancel</a>

And send becomes:

和发送就变成:

<a class="button" href="javascript:" onclick='$("#action").attr("name","send");$("#frmCompose").submit();'>Send</a>

Hope this helps

希望这有助于

#6


0  

I think the easiest way is just to create an <input type="hidden" /> with the name you want, like this:

我认为最简单的方法就是创建一个,其中包含您想要的名称,如下所示:

<input type="hidden" name="cancel" />
<a class="button" href="javascript:" onclick="$('#frmCompose').submit();">Cancel</a>

#7


0  

may be you not need to use <a> ?

也许你不需要用 ?

html:

html:

<button class="alike">Test</button>
<a href="#">Test</a>​

css:

css:

button.alike,a {
 border: 0px;   
 text-decoration: underline;
 color: #00E;
 width: auto;
 cursor: pointer;
 background-color: inherit;
 font-family: 'Times New Roman';
 font-size: 16px;
}​

#1


1  

If adding name="cancel" to your doesn't work, it sounds like you might have to get a little fancy with your javascript. Something like:

如果在你的javascript中添加name="cancel"不起作用,那么你可能需要对你的javascript感兴趣。喜欢的东西:

<input type="hidden" name="placeholder" value="true" />
<a class="button" name="cancel" href="javascript:" onclick="$(this).prev().attr('name', 'cancel'); $('#frmCompose').submit();">Cancel</a>

#2


2  

Uglyish, but use a hidden form field:

但是使用一个隐藏的表单字段:

<input type="hidden" id="clickedname" name="" value="" />

and

<a class="button" name="cancel" href="javascript:" onclick="$('#clickedname').value = this.name; $('#frmCompose').submit();">Cancel</a>
                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^

Adjust the name/value assignments to suit - I can't remember offhand exactly how image inputs submit themselves.

调整名称/值分配以适应——我不记得图像输入是如何自动提交的。

#3


2  

You'll need to use JS to, for example, put a value into a hidden field for the submit, and submit.

您将需要使用JS,例如,将一个值放入隐藏字段中以便提交和提交。

I'd recommend writing a tiny utility function that replaces your onclick attribute value. Better yet, attach the functionality after DOM ready and keep things unobtrusive and localized.

我建议编写一个小的实用函数来替换onclick属性值。更好的是,在DOM就绪后附加功能,保持事物不突兀和本地化。

<a class="button" href="#" onclick="submit('cancel')">Cancel</a>

And submit does what you'd expect, fills the hidden field, and submits the form. If you really can't change the back end at all then you can change the name of the hidden field as well, but ugh; seems like changing the back end to check for an "action" field or something is cleaner.

提交完成您所期望的,填充隐藏字段,并提交表单。如果你真的不能改变后端那么你也可以改变隐藏字段的名字,但是;似乎要更改后端以检查“动作”字段或其他更干净的东西。

#4


1  

Only form elements (<input>, <button>, <textarea>, <select>, etc.) submit values to a form. For an <a> tag to do so, you'd have to use JavaScript to add the value to a form.

只有表单元素(

One way is to add a hidden form element, and set its name/value.

一种方法是添加一个隐藏的表单元素,并设置它的名称/值。

<a class="button" name="cancel" href="#">Cancel</a>
<input type="hidden" id="buttonClicked" />

Then using JavaScript (jQuery):

然后使用JavaScript(jQuery):

$(function(){
    $('a.button').click(function(e){
        e.preventDefault();
        $('#buttonClicked').prop({
            name: $(this).prop('name'),
            value: $(this).prop('name')
        });
        $('#frmCompose').submit();
    });
});

#5


1  

You can add a single hidden field to the form

您可以向窗体添加一个隐藏字段

<input type="hidden" id="action" value=""/>

Then set the value of action in the onclick

然后在onclick中设置动作的值

$("#action").attr("name","---ActionHere---");

So cancel becomes:

所以取消就变成:

<a class="button" href="javascript:" onclick='$("#action").attr("name","cancel");$("#frmCompose").submit();'>Cancel</a>

And send becomes:

和发送就变成:

<a class="button" href="javascript:" onclick='$("#action").attr("name","send");$("#frmCompose").submit();'>Send</a>

Hope this helps

希望这有助于

#6


0  

I think the easiest way is just to create an <input type="hidden" /> with the name you want, like this:

我认为最简单的方法就是创建一个,其中包含您想要的名称,如下所示:

<input type="hidden" name="cancel" />
<a class="button" href="javascript:" onclick="$('#frmCompose').submit();">Cancel</a>

#7


0  

may be you not need to use <a> ?

也许你不需要用 ?

html:

html:

<button class="alike">Test</button>
<a href="#">Test</a>​

css:

css:

button.alike,a {
 border: 0px;   
 text-decoration: underline;
 color: #00E;
 width: auto;
 cursor: pointer;
 background-color: inherit;
 font-family: 'Times New Roman';
 font-size: 16px;
}​