简体   繁体   English

一个简单的JavaScript问题

[英]A simple javascript issue

The following code resides on a wordpress site. 以下代码位于wordpress网站上。 It is a donation landing page where you can select from a dropdown list, a category for your donation. 这是捐赠的登录页面,您可以从下拉列表中选择捐赠的类别。 Upon selecting a category a button shows and allows the user to continue with their donation(currently disabled). 选择类别后,将显示一个按钮,并允许用户继续其捐赠(当前被禁用)。 Works great in Safari, IE and Firefox, nothing. 在Safari,IE和Firefox中都能很好地运行,什么也没有。 Can anyone provide any help. 任何人都可以提供任何帮助。 Thanks in advance. 提前致谢。 Code to follow. 遵循的代码。

Dave 戴夫

    <p class="donate2">Donate Now</p>
    <table cellpadding="0" cellspacing="0" style="padding:0; width:890px; border:0 !important"><tr><td style="padding:0; border:0 !important;"><p>Our Mission is to give hope and a future back to children who are suffering through debilitating and life threatening illness. We are so very fortunate to have a wonderful team of volunteers and a base of generous donors which support these essential programs for children stricken with serious illness.</p>
    <p>Please use the following link to the right to make your payment via our secure checkout. All donations are 100% tax deductible. Payments for events may only be partially tax deductible. The Gambino Medical and Science Foundation is a 501(c) NonProfit, Tax Exempt Organization. (Federal Tax Exempt No. 13-3586460)</p></td>
    <td style="padding:0; border:0 !important">

    <script>
        function click(frm,value,button) {
            alert(value);
            frm.LinkId.value = value;
            if (value != "") {
                alert('Works');
                document.getElementById(button).style.display = "block"; 
            } else {
                alert('Works2');
                document.getElementById(button).style.display = "none"; 
            }
        }
    </script>

    <form style="float:right; margin-bottom: 100px; margin-left: 105px;" name="PrePage" id="Prepage" method ="post" action= "https://Simplecheckout.authorize.net/payment/CatalogPayment.aspx">
    <select size="1" width="100" name="selectbox" id="selectbox" onchange="click(document.PrePage,document.PrePage.selectbox.options[selectedIndex].value,'button');" >
    <option selected value=""></option>
    <option value="4671dbc4-02ca-459d-8a46-c0783d38319e">General Donation</option>
    <option value="2">Dinner</option>
    </select>
    <input type="hidden" name="LinkId" id="LinkId" value="" /><input id="button" style="display:none;" type="image" src ="wp-content/themes/adsimple/i/donate_button.gif" /></form></td></tr></table>

Change the function's name to notClick and it will work. 将该函数的名称更改为notClick ,它将起作用。

The reason why your original code works in Chrome, but not in IE and (some versions of) Firefox is that the <select> tag has a click() method in the latter two, but not in Chrome. 您的原始代码可以在Chrome中运行,但不能在IE和Firefox(某些版本)中运行的原因是<select>标记在后两个中具有click()方法,而在Chrome中却没有。

Therefore, the click() in <select onchange="click()"> gets interpreted as this.click() , which actually simulates a click on the select box. 因此, click()<select onchange="click()">被解释为this.click()这实际上模拟在选择框的点击。

In Chrome, such function does not exist, so click() gets interpreted as window.click() , which is the function you defined. 在Chrome中,该功能不存在,因此click()被解释为window.click() ,这是您定义的功能。

try this: 尝试这个:

<select size="1" width="100" name="selectbox" id="selectbox" onchange="click(document.PrePage,document.PrePage.selectbox.options[this.selectedIndex].value,'button');" >
<option selected value=""></option>
<option value="4671dbc4-02ca-459d-8a46-c0783d38319e">General Donation</option>
<option value="2">Dinner</option>
</select>

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

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