0

我在下面使用此代码,但似乎我的 setValue() 方法不起作用。有人可以指出这段代码有什么问题吗?

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script language="javascript"> 
function rand ( n )
{
    document.getElementById("orderRefId").value =  ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function setValue(amount1)
{
    myValue = amount1;
    document.getElementById("amount").value = myValue;
  }


</script>
</head>
<body onLoad="rand( 2000000 )">
        <!-- 
            Note: https://www.pesopay.com/b2c2/eng/payment/payForm.jsp for live payment URL
                  https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp for test payment URL
        -->
        <form method="POST" name="frmPayment" action="https://test.pesopay.com/b2cDemo/eng/payment/payForm.jsp">
        <table>
        <tbody>
        <tr>
            <td>Order Reference No. (your reference number for every transaction that has transpired):</td> 
            <td><input type="text" id="orderRefId" name="orderRef" value="Test-001"/></td>
        </tr>   
        <tr>
            <td>Amount:</td>
            <td><input type="text" onLoad = "setValue()" name="amount" value=""/></td>

        </tr>
        <tr>
            <td>Currency Code - "608" for Philippine Peso, "840" for US Dollar:</td>
            <td><input type="text" name="currCode" value="608"/></td>
        </tr>   
        <tr>
            <td>Language:</td>
            <td><input type="text" name="lang" value="E"/></td>
        </tr>   
        <tr>
            <td>Merchant ID (the merchant identification number that was issued to you - merchant IDs between test account and live account are not the same):</td> 
            <td><input type="text" name="merchantId" value="18056869"/></td>
        </tr>
        <tr>    
            <td>Redirect to a URL upon failed transaction:</td>
            <td><input type="text" name="failUrl" value="http://www.yahoo.com?flag=failed"/></td>
        </tr>   
        <tr>
            <td>Redirect to a URL upon successful transaction:</td>
            <td><input type="text" name="successUrl" value="http://www.google.com?flag=success"/></td>
        </tr>
        <tr>
            <td>Redirect to a URL upon canceled transaction:</td>
            <td><input type="text" name="cancelUrl" value="http://www.altavista.com?flag=cancel"/></td>
        </tr>
        <tr>
            <td>Type of payment (normal sales or authorized i.e. hold payment):</td> 
            <td><input type="text" name="payType" value="N"/></td>
        </tr>
        <tr>    
            <td>Payment Method - Change to "ALL" for all the activated payment methods in the account, Change to "BancNet" for BancNet debit card payments only, Change to "GCASH" for GCash mobile payments only, Change to "CC" for credit card payments only:</td>
            <td><input type="text" name="payMethod" value="ALL"/></td>
        </tr>
        <tr>    
            <td>Remark:</td>
            <td><input type="text" name="remark" value="Asiapay Test"/></td>
        </tr>
        <!--<tr>    
            <td>Redirect:</td>
            <td><input type="text" name="redirect" value="1"/></td>
        </tr>-->
        <tr>
            <td></td>
        </tr>   

        <input type="submit" value="Submit">
        </tbody>
        </table>
        </form>
    </body>
    </html> 

注意:变量“amount1”来自我的 android。它不会导致问题,因为我在其他代码中使用它。

我将非常感谢任何想法。

4

3 回答 3

1

JavaScript 在 WebView 中处于禁用的默认设置中。您需要先激活它。

YourWebView.getSettings().setJavaScriptEnabled(true);

您还需要更正您的 JavaScript。您调用 function document.getElementById(...),但您的输入元素没有 Id 而是一个名称。所以你需要打电话document.getElementsByName(...)[0]

于 2012-08-03T05:39:00.220 回答
1

1.你没有id为“amount”的DOMInputElement。您需要像这样更改html:

<input type="text" onLoad = "setValue()" name="amount" id="amount" value=""/>

或者像这样的js:

function setValue(amount1)
{
    myValue = amount1;
    document.frmPayment.amount.value = myValue;
}

2.第二个问题是您不能将 onLoad 事件附加到输入元素。您可以做的是将 <script/> 与 setValue() 调用或将您的 <body> 标记更改为:

<body onLoad="rand(200000);setValue();">
于 2012-08-03T05:39:49.053 回答
0
           function text() {
        var dt = new Date();
        dt.format("dd-mmm-yyyy");
        var newdt = dt.getFullYear();
        var tt = document.getElementById("ctl00_ContentPlaceHolder1_txtPolicyStartDate").value;           
        var dt2 = new Date.parseLocale(tt, 'dd-MMM-yyyy');     

        dt2.setFullYear(dt2.getFullYear() + 1);
        dt2.setDate(dt2.getDate() - 1);
        document.getElementById("ctl00_ContentPlaceHolder1_txtPolicyExpiryDate").value = dt2.format("dd-MMM-yyyy");
        return dt2;
    }
于 2013-01-21T12:10:34.950 回答