1

我正在为正在创建的网页制作消息传递系统。我想单击某人姓名旁边的按钮,并让他们的姓名出现在对话框中,以了解我正在将其发送给他们。

这是我试图让它出现的DIV。无论我点击哪个人,模式都可以正常工作,它会将相同的名称带回“to”字段。

<div id='chatPop' style="display: none;">
      Messages
      <hr>
      To: <?Php echo $userId ?>
      <br><br><br>
      From:
      <br><br><br>
      Message:-<textarea> </textarea>
</div>

这是我的 JS,它已经打开了对话框:

function doPop(userId)
{
$("#chatPop")

.dialog({
      float: top,
      resizable: true,
      height: 350,
      modal: true,
      buttons: {
        Send: function() {
          $(this).dialog("close");
        }
      }
    });
      }

这是我的 PHP,它位于 div 内部并且正在工作,但没有传递我想要的 $userId:

              <?php
              while ($row = mysqli_fetch_array($result))
              {
                echo "<li>";
                echo "<a>";
                $userId = $row ['userId'];
                echo $userId;
                echo " <input type=button value=chat onclick=doPop('$userId')>";
                echo "</a>";
                echo "</li>";
              }
              mysqli_close($con1);
              ?>
4

4 回答 4

0

你可以这样做:

HTML

<div id='chatPop' style="display: none;">
      Messages
      <hr>
      To: <span id="userid"></span>
      <br><br><br>
      From:
      <br><br><br>
      Message:-<textarea> </textarea>
</div>

Javascript

function doPop(userId)
{
   $("#userid").html(userId);

   $("#chatPop").dialog({
      float: top,
      resizable: true,
      height: 350,
      modal: true,
      buttons: {
        Send: function() {
          $(this).dialog("close");
        }
      }
   });
}
于 2013-11-05T11:26:01.627 回答
0

将您的对话框标记更改为此...

<div id='chatPop' style="display: none;">
      Messages
      <hr>
      To: <input type="text" name="to" id="send-to" />
      <br><br><br>
      From: <input type="text" name="from" id="sent-from" />
      <br><br><br>
      Message:-<textarea name="message" id="message"> </textarea>
</div>

并将您的对话功能更改为此...

function doPop(userId) {
    $("#send-to").val(userId);
    $("#chatPop")
        .dialog({
            float: top,
            resizable: true,
            height: 350,
            modal: true,
            buttons: {
                Send: function() {
                    $(this).dialog("close");
                }
            }
        });
}

输入的名称属性适用于您将其包装在您希望提交的表单中(假设您将Send为此使用按钮回调)。ID 是为了让您可以使用 javascript 引用事物。

于 2013-11-05T11:31:31.637 回答
0

将您的对话框标记更改为此

<div id='chatPop' style="display: none;">
      Messages
      <hr>
      To: <input type="text" name="to" id="send-to" />
      <br><br><br>
      From: <input type="text" name="from" id="sent-from" />
      <br><br><br>
      Message:-<textarea name="message" id="message"> </textarea>
</div>

并将您的对话功能更改为此...

function doPop(userId) {
    $("#send-to").val(userId);
    $("#chatPop")
        .dialog({
            float: top,
            resizable: true,
            height: 350,
            modal: true,
            buttons: {
                Send: function() {
                    $(this).dialog("close");
                }
            }
    });

}

于 2013-11-25T16:10:47.270 回答
0

将您的对话框标记更改为此

<div id='chatPop' style="display: none;">
      Messages
      <hr>
      To: <input type="text" name="to" id="send-to" />
      <br><br><br>
      From: <input type="text" name="from" id="sent-from" />
      <br><br><br>
      Message:-<textarea name="message" id="message"> </textarea>
</div>

并将您的对话功能更改为此...

function doPop(userId) {
    $("#send-to").val(userId);
    $("#chatPop")
        .dialog({
            float: top,
            resizable: true,
            height: 350,
            modal: true,
            buttons: {
                Send: function() {
                    $(this).dialog("close");
                }
            }
    });
}
于 2013-11-26T10:29:29.823 回答