Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中设置会话或php变量?_Php_Javascript_Html - Fatal编程技术网

在javascript中设置会话或php变量?

在javascript中设置会话或php变量?,php,javascript,html,Php,Javascript,Html,我正在为两种语言(英语和印地语)制作一个简单的html表单,因此我为ex//印地语显示了这两种语言的链接 ...... ...... 不能使用java脚本更改PHP代码。因为PHP代码是在服务器上运行的。发送到客户端,然后可以对结果运行java脚本。所以你有两个选择: 要么两个表格都寄。使用css隐藏两者。onclick显示相应的表单 或者AJAX解决方案。然后用户单击链接。使用java脚本从服务器(另一个URL)获取表单并显示在页面中。您不能使用java脚本更改PHP代码。因为PHP代码是在服

我正在为两种语言(英语和印地语)制作一个简单的html表单,因此我为ex
//印地语显示了这两种语言的链接
......
......

不能使用java脚本更改PHP代码。因为PHP代码是在服务器上运行的。发送到客户端,然后可以对结果运行java脚本。所以你有两个选择:

要么两个表格都寄。使用css隐藏两者。onclick显示相应的表单


或者AJAX解决方案。然后用户单击链接。使用java脚本从服务器(另一个URL)获取表单并显示在页面中。

您不能使用java脚本更改PHP代码。因为PHP代码是在服务器上运行的。发送到客户端,然后可以对结果运行java脚本。所以你有两个选择:

要么两个表格都寄。使用css隐藏两者。onclick显示相应的表单


或者AJAX解决方案。然后用户单击链接。使用java脚本从服务器获取表单(另一个URL)并在页面中显示。

您可以向两个表单添加一个隐藏字段,其中包含所选语言

<form action="" method="post" name="englishform">
  <input type="hidden" name="language" value="en" />
  ...
</form>

<form action="" method="post" name="hindiform">
  <input type="hidden" name="language" value="hi" />
  ...
</form>

...
...

您可以在两个表单中添加一个隐藏字段,其中包含所选语言

<form action="" method="post" name="englishform">
  <input type="hidden" name="language" value="en" />
  ...
</form>

<form action="" method="post" name="hindiform">
  <input type="hidden" name="language" value="hi" />
  ...
</form>

...
...

好吧,假设您只想根据超链接隐藏或显示不同的表单:

<a class="switcher" rel="englishform" href="#"> English </a> / <a class="switcher" rel="hindiform" href="#">Hindi</a>

<form action="" method="post" id="englishform" style="display:none">
......
</form>

<form action="" method="post" id="hindiform" style="display:none">
......
</form>


<script>

    $("a.switcher").click(function(e){
        var name = $(this).attr("rel");

        $("#" + name).show();

        e.preventDefault();
    });

</script>
/
......
......
$(“a.switcher”)。单击(函数(e){
var name=$(this.attr(“rel”);
$(“#”+name.show();
e、 预防默认值();
});

好吧,假设您只想根据超链接隐藏或显示不同的表单:

<a class="switcher" rel="englishform" href="#"> English </a> / <a class="switcher" rel="hindiform" href="#">Hindi</a>

<form action="" method="post" id="englishform" style="display:none">
......
</form>

<form action="" method="post" id="hindiform" style="display:none">
......
</form>


<script>

    $("a.switcher").click(function(e){
        var name = $(this).attr("rel");

        $("#" + name).show();

        e.preventDefault();
    });

</script>
/
......
......
$(“a.switcher”)。单击(函数(e){
var name=$(this.attr(“rel”);
$(“#”+name.show();
e、 预防默认值();
});

我对javascript知之甚少,但如果你懂了,你可以做以下几点:

<a href="en">English</a> / <a href="hi">Hindi</a>

<form action="" method="post" data-lang="en">
    ...
</form>

<form action="" method="post" data-lang="hi">
    ...
</form>
或者不使用jQuery:

<? if(!$_GET['lang'] || ($_GET['lang'] != "en" && $_GET['lang'] != "hi")){ ?>
<a href="form.php?lang=en">English</a> / <a href="form.php?lang=hi">Hindi</a>
<? }elseif($_GET['lang'] == "en"){ ?>
<form action="" method="post">
    ...
</form>
<? }elseif($_GET['lang'] == "hi"){ ?>
<form action="" method="post" data-lang="hi">
    ...
</form>
<?
}
?>

/ 
...
...

我对javascript知之甚少,但如果你懂了,你可以做以下几点:

<a href="en">English</a> / <a href="hi">Hindi</a>

<form action="" method="post" data-lang="en">
    ...
</form>

<form action="" method="post" data-lang="hi">
    ...
</form>
或者不使用jQuery:

<? if(!$_GET['lang'] || ($_GET['lang'] != "en" && $_GET['lang'] != "hi")){ ?>
<a href="form.php?lang=en">English</a> / <a href="form.php?lang=hi">Hindi</a>
<? }elseif($_GET['lang'] == "en"){ ?>
<form action="" method="post">
    ...
</form>
<? }elseif($_GET['lang'] == "hi"){ ?>
<form action="" method="post" data-lang="hi">
    ...
</form>
<?
}
?>

/ 
...
...

$(函数(){
$(“#showEnglishForm”)。单击(函数()
{
$(“#hindiFormDiv”).hide();
$(“#英语formdiv”).show();
});
$(“#showHindForm”)。单击(函数()
{
$(“#hindiFormDiv”).show();
$(“#英语formdiv”).hide();
});
});
英语形式
...
印地语形式
...

$(函数(){
$(“#showEnglishForm”)。单击(函数()
{
$(“#hindiFormDiv”).hide();
$(“#英语formdiv”).show();
});
$(“#showHindForm”)。单击(函数()
{
$(“#hindiFormDiv”).show();
$(“#英语formdiv”).hide();
});
});
英语形式
...
印地语形式
...

您希望超链接转到一个新页面(超链接实际上是什么)还是只希望有一个按钮可以在不重新加载页面的情况下交换表单?如果很容易,请重新加载同一页面,或者在单击该链接时交换表单您希望超链接转到一个新页面(超链接实际上是什么)或者你只是想要一个按钮来交换表单而不需要重新加载页面?如果很容易,可以重新加载相同的页面,或者在单击该链接时交换表单使用css隐藏两个表单,但我不知道如何识别单击了哪个链接?你有一个名为的函数。单击使用css隐藏两个表单,但我不知道如何识别单击了哪个链接?您有一个名为的函数。再次点击