登录 - 根据选择更改表单操作?

发布于 2024-08-15 04:48:01 字数 898 浏览 1 评论 0原文

我在一个黑手党游戏中有这个脚本,我有 4 个世界/服务器。我有index.php,我想通过从选项中选择它来直接登录到其中一台服务器

我有此代码,我需要更改表单操作

<form action="/ro1/index.php?action=login" method="post">
<input id="user" name="user" class="text" type="text" value="Name"/><br>
<input name="clear" type="hidden" value="true" />
<input id="password" name="password" type="password" value="Pass"/>

<select id="server_select" class="server_select" name="server">
<option value="/ro1/index.php?action=login" selected >World 1</option>
<option value="/ro2/index.php?action=login">World 2</option>
<option value="/ro3/index.php?action=login">World 3</option>
<option value="/ro4/index.php?action=login">World 4</option>
</select>
<input type="image" src="graphic/index/login1.png" name="submit">
</form>

希望您明白我需要什么。

I have this script on a mafia game where I have 4 worlds/servers. I have index.php where I want to login directly to one of the servers by selecting it from a option

I have this code and I need to change form action

<form action="/ro1/index.php?action=login" method="post">
<input id="user" name="user" class="text" type="text" value="Name"/><br>
<input name="clear" type="hidden" value="true" />
<input id="password" name="password" type="password" value="Pass"/>

<select id="server_select" class="server_select" name="server">
<option value="/ro1/index.php?action=login" selected >World 1</option>
<option value="/ro2/index.php?action=login">World 2</option>
<option value="/ro3/index.php?action=login">World 3</option>
<option value="/ro4/index.php?action=login">World 4</option>
</select>
<input type="image" src="graphic/index/login1.png" name="submit">
</form>

Hope you understood what I need.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫腻 2024-08-22 04:48:05

最好在服务器上处理用户选择,并在那里执行重定向或根据需要处理操作。但如果你真的想在客户端处理它,你应该使用 javascript。包含 jQuery 库后,以下内容应该可以工作:

$('#server_select').change(function(){
   $(this).parents('form').attr('action', $(this).val());
});

更具体地说,将以下代码添加到 html 文件的 head 部分。

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
  $('#server_select').change(function(){
    $(this).parents('form').attr('action', $(this).val());
  });
</script>

Its probably best to handle the users selection on the server, and either perform a redirect there or handle the action as needed. But if you really wanted to handle it on the client side you should use javascript. The following should work after including the jQuery library:

$('#server_select').change(function(){
   $(this).parents('form').attr('action', $(this).val());
});

To be more specific add the following code to the head section of your html file.

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
  $('#server_select').change(function(){
    $(this).parents('form').attr('action', $(this).val());
  });
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文