IE浏览器的一个按钮元素上点击时发出内部HTML [英] IE sends inner HTML when clicking on a button element

查看:345
本文介绍了IE浏览器的一个按钮元素上点击时发出内部HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的HTML在我的网页(简化)。

I have the following html in my webpage (simplified).

<button type="submit" name="action" value="ButtonA">Click Here</button>

在Firefox中,它提交按钮a作为行动形式值的值。然而,在IE7,它提交点击这里。有什么办法解决呢?我不希望使用的输入标签,因为我需要能够自定义文本,而不会影响发送回窗体(本地化)的值。基本上,我希望能够有同名的多个按钮,并且根据自己的价值,提交时做不同的动作。是否有任何容易让IE在这种情况下,正确的行为?

In Firefox, it submits "ButtonA" as the value for the "action" form value. However, in IE7, it submits "Click Here". Is there any way to resolve this? I don't want to use input tags, because I need to be able to customize the text without affecting the values sent back to the form (localization). Basically, I want to be able to have multiple buttons with the same name, and depending on their value, do a different action when submitted. Is there any easy with to get IE to act correctly in this case?

[详细]

也许我应该更清楚,但我不能使用

Maybe I should be more clear, but I can't use

<input type="submit" name="Action" value="ButtonA">

因为我需要能够改变本地化规则显示的文本,而不会影响与表单提交按钮的实际值。

because I need to be able to change the text displayed for localization rules, without affecting the actual value of the button that's submitted with the form.

[详细]

要阐述还要多,基本上,我想按钮能够说保存或Sauver根据不同的语言,但没有提交到服务器的更改值。我也希望有同名的多个按钮,并根据不同的值,做一些事情,而不是依赖于该按钮的名称和测试,如果有该按钮的值。在code已经从这个角度写的,我只是希望能够改变的值显示的文字,没有现有服务器端处理code。

To elaborate even more, Basically, I want the button to be able to say "Save" or "Sauver" depending on the language, but not have the value submitted to the server change. I also want to have multiple buttons with the same name, and depending on the value, do something, rather than depending on the button name, and testing if there is a value for that button. The code is already written from that perspective, and I just want to be able to change the displayed text in the values, without existing server side processing code.

下面是一个很好的链接<一个href=\"http://allinthehead.com/retro/330/coping-with-internet-explorers-mishandling-of-buttons\">explanation问题,与一些可能的变通。

Here is a link with a very good explanation of the problem, with some possible work arounds.

推荐答案

一个解决方案是使用Javascript和隐藏的字段

One solution is to use Javascript and a hidden field

   <input type="hidden" name="actionparam" value="DoNothing">
   <input type="button" onclick="OnSubmitForm('ActionA')" Value="Click Here for A" />
   <input type="button" onclick="OnSubmitForm('ActionB')" Value="Click Here for B" />


   function OnSubmitForm(actionname) {
	var f = document.frm;
	f.actionparam.value = actionname;
	f.submit();
 }

这可以作为一个隐藏CATPCHA还,你可以在JavaScript函数中添加一些客户端验证

This works as a hidden CATPCHA also, and you can add some client validation in the javascript function

既然你说你要降低非JavaScript的浏览器,就可以使用这个版本,即只允许一个默认操作的人没有的JavaScript

Since you say you want to degrade to non-javascript browsers, you can use this version, that allow only one default action to the people with no javascript

额外的按钮都在HTML禁用,但随后重新启用使用JavaScript。

经测试code:

The extra buttons are disabled in HTML but then re-enabled with javascript.
Tested code:

<html>
<head>
    <script type="text/javascript">
    <!--
    function OnSubmitForm(actionname) {
    		var f = document.frm;
    		f.actionparam.value = actionname;
    		f.submit();
    }
    //-->
    </SCRIPT>
</head>
<body>
   <noscript>
        <div style="background-color: yellow; margin: 20px;" >
            You are using a limited version of the site because you don't have Javascript enabled
        </div>
    </noscript>


   <h1>form</h1>
    <form name="frm" method="post">
    <input type="hidden" name="actionparam" value="DefaultAction" />
    <button name="defaultbutton" type="submit">default action</button>
    <button name="extrabutton1" disabled onclick="OnSubmitForm('ExtraAction1')">Extra action 1</button>
    <button name="extrabutton2" disabled onclick="OnSubmitForm('ExtraAction2')">Extra action 2</button>
    </form>


   <h1>Results</h1>
   <h2>forms collection</h2>
   <ol>
   <%
   For x = 1 To Request.Form.count()
      Response.Write("<li>" + Request.Form.key(x) + "=" + Request.Form.item(x) + "</li>")
   Next
   %>
   </ol>


    <script type="text/javascript">
    <!--
    document.frm.extrabutton1.disabled = false;
    document.frm.extrabutton2.disabled = false;
    //-->
    </SCRIPT>

</body>
</html>

这篇关于IE浏览器的一个按钮元素上点击时发出内部HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆