Home >Backend Development >PHP Tutorial >javascript - PHP嵌入表单提交遇到问题关于取onclick事件产生的值 求大神指教

javascript - PHP嵌入表单提交遇到问题关于取onclick事件产生的值 求大神指教

WBOY
WBOYOriginal
2016-06-06 20:48:241037browse

求助啊

<code class="lang-javascript">echo "
<br>
    0:
<form action="qashownumber.php" method="GET" target="qashownumber">
        <button type="submit" value="$nownumber" name="Answer" onclick="onclickadd()">否 NO</button>
    </form>
    <br>
<form action="qashownumber.php" method="GET" target="qashownumber">
    <button type="submit" name="Answer" onclick="onclickadd()" value="var('demo')">是 YES</button>
    <script>
        var a=0;
        function onclickadd()
        {
            a++;
            document.getElementById('demo').innerHTML=a;
        }
    </script>
    <p id="demo"></p>
    </form>
";
</code>

怎么把a的值赋给这个get方法的value进去?

回复内容:

求助啊

<code class="lang-javascript">echo "
<br>
    0:
<form action="qashownumber.php" method="GET" target="qashownumber">
        <button type="submit" value="$nownumber" name="Answer" onclick="onclickadd()">否 NO</button>
    </form>
    <br>
<form action="qashownumber.php" method="GET" target="qashownumber">
    <button type="submit" name="Answer" onclick="onclickadd()" value="var('demo')">是 YES</button>
    <script>
        var a=0;
        function onclickadd()
        {
            a++;
            document.getElementById('demo').innerHTML=a;
        }
    </script>
    <p id="demo"></p>
    </form>
";
</code>

怎么把a的值赋给这个get方法的value进去?

<code class="lang-javascript"><form action="qashownumber.php" method="GET" target="qashownumber">
    <button type="submit      " name="Answer      " onclick="onclickadd()" id="demo        ">是 YES</button>
    <script>
    var a=0;
    function onclickadd()
    {
        a++;
        document.getElementById('demo').value=a;
    }
    </script>
</form>
</code>

其实这样就能把JS中的值给到表单里作为值提交了,很方便的方法,对于刚起步的我而言,终于搞出来了。话说越学越高级的方法会出现,现在只要能用得惯就可以了,不管代码清清爽爽这件事情了,哈哈!

犯得着用表单么,直接用AJAX呗。(原生的AJAX不大会写,就给你写jQuery版的吧)

<code>$.get('qashownumber.php?Answer=abc', function(d) {
     $('#qashownumber').html(d);
});
</code>

hidden控件、提交时更改form的action等等,无数种方法,其实不难想到,建议楼主多谷歌。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn