【问题标题】:form with javascript code in wordpress在 wordpress 中使用 javascript 代码形成表单
【发布时间】:2014-08-06 06:35:10
【问题描述】:

我想用上面提到的 javascript 代码在 wordpress 中创建相同的表单。请指导我如何创建类似的表单以及在何处发布此 javascript 代码。当我们将此代码保存在 html 文档中时,此代码可以完美运行。但我不知道在 wordpress 中将这段代码保存在哪里。 非常感谢

<script type="text/javascript">
    function DisplayPrice(price){
        var val1 = 0;
        for( i = 0; i < document.form1.price.length; i++ ){
            if( document.form1.price[i].checked == true ){
                val1 = document.form1.price[i].value;
            }
        }

        var val2 = 0;
        for( i = 0; i < document.form2.price2.length; i++ ){
            if( document.form2.price2[i].checked == true ){
                val2 = document.form2.price2[i].value;
            }
        }

        var sum=parseInt(val1) + parseInt(val2);
        document.getElementById('totalSum').value=sum;
    }
    </script>
 </head>
 <body>
   Choose a number:<br>
   <form name="form1" id="form1" runat="server">
    <br>
    <input id="rdo_1" type="radio" value="159" name="price"                              onclick="DisplayPrice(this.value);">159
    <br>
    <input id="rdo_2" type="radio" value="259" name="price" onclick="DisplayPrice(this.value);">259
    <br>
       </form>

    Choose another number:<br>
     <form name="form2" id="form2" runat="server">
    <br>
    <input id="rdo_1" type="radio" value="345" name="price2" onclick="DisplayPrice(this.value);">345
    <br>
    <input id="rdo_2" type="radio" value="87" name="price2" onclick="DisplayPrice(this.value);">87
    <br>
   </form>
   <input type="text" name="totalSum" id="totalSum" value="" size="2" readonly="readonly">


    </body>

【问题讨论】:

标签: javascript wordpress forms


【解决方案1】:

有两种方法可以将此代码添加到wordpress

1 .在您的主题文件夹中 -> 您激活的主题 -> index.php

2 。在您的插件文件夹中 -> 使用任何名称创建新的插件文件夹 -> 通过在插件中创建 index.php 文件来添加此代码

在 index.php 的顶部添加以下行

/* 插件名称:插件名称

版本:1.0

插件 URI:

说明:

作者:

作者网址:

使用您提供的名称激活插件。

表格测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多