18910140161

HTML-如何在php函数中“链接”两个对象(如关键字及其同义词)?-堆栈溢出

顺晟科技

2022-10-19 14:24:55

112

我正在使用php、html、css和JavaScript创建表单。

在此表单中,用户需要选择几个关键字及其同义词。

如下所示:

     <form action="create.php" class="col-md-10 offset-md-1" method="post"> 
    <div class="form-group" id="duplicateKeyWordAndSynonym">
    <label for="keyWord">Type a keyword.</label>
    <textarea class="form-control" id="terms" name="terms[]"></textarea> <br/>
    <label for="synonym">Type the synonyms of your keyword.</label>
    <textarea class="form-control" id="synonym" name="synonym[]"></textarea> <br/>
    </div>        
    <button class="glass-button" type="button" id="add">click here to add more keywords and 
    synonyms.</button>
    </form>
    <script>
    //https://api.jquery.com/click/
    $("#add").click(function () {
    //https://api.jquery.com/append/
    $("#duplicateKeyWordAndSynonym").append('here is the code to duplicate the keywords and 
    synonyms part.');
                });
   </script>

现在,我必须将关键字连接到“create.php”上的同义词,以便将其发送到后端。

我试过几种方法,但似乎都不起作用。

这是我第一次尝试:

     <form action="create.php" class="col-md-10 offset-md-1" method="post"> 
    <div class="form-group" id="duplicateKeyWordAndSynonym">
    <label for="keyWord">Type a keyword.</label>
    <textarea class="form-control" id="terms" name="terms[]"></textarea> <br/>
    <label for="synonym">Type the synonyms of your keyword.</label>
    <textarea class="form-control" id="synonym" name="synonym[]"></textarea> <br/>
    </div>        
    <button class="glass-button" type="button" id="add">click here to add more keywords and 
    synonyms.</button>
    </form>
    <script>
    //https://api.jquery.com/click/
    $("#add").click(function () {
    //https://api.jquery.com/append/
    $("#duplicateKeyWordAndSynonym").append('here is the code to duplicate the keywords and 
    synonyms part.');
                });
   </script>

我尝试的最后一件事是:

     <form action="create.php" class="col-md-10 offset-md-1" method="post"> 
    <div class="form-group" id="duplicateKeyWordAndSynonym">
    <label for="keyWord">Type a keyword.</label>
    <textarea class="form-control" id="terms" name="terms[]"></textarea> <br/>
    <label for="synonym">Type the synonyms of your keyword.</label>
    <textarea class="form-control" id="synonym" name="synonym[]"></textarea> <br/>
    </div>        
    <button class="glass-button" type="button" id="add">click here to add more keywords and 
    synonyms.</button>
    </form>
    <script>
    //https://api.jquery.com/click/
    $("#add").click(function () {
    //https://api.jquery.com/append/
    $("#duplicateKeyWordAndSynonym").append('here is the code to duplicate the keywords and 
    synonyms part.');
                });
   </script>

不起作用。我该怎么办?

============================================ 编辑:谢谢你的评论,伙计们!我是这样解决这个问题的:

     <form action="create.php" class="col-md-10 offset-md-1" method="post"> 
    <div class="form-group" id="duplicateKeyWordAndSynonym">
    <label for="keyWord">Type a keyword.</label>
    <textarea class="form-control" id="terms" name="terms[]"></textarea> <br/>
    <label for="synonym">Type the synonyms of your keyword.</label>
    <textarea class="form-control" id="synonym" name="synonym[]"></textarea> <br/>
    </div>        
    <button class="glass-button" type="button" id="add">click here to add more keywords and 
    synonyms.</button>
    </form>
    <script>
    //https://api.jquery.com/click/
    $("#add").click(function () {
    //https://api.jquery.com/append/
    $("#duplicateKeyWordAndSynonym").append('here is the code to duplicate the keywords and 
    synonyms part.');
                });
   </script>

顺晟科技:

可以通过两种方式提交表单:

1--在javascript中,通过将脚本(document.getElementById(“myForm”).submit();其中myForm是id表单。

2--在php中,在按钮级别放置type=“submit”而不是“button”。

您可以通过$_post['terms']和$_post['synonyme']

检索页面“create.php”中的数据
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航