如何在脚本外部获取Javascript变量 [英] How to get Javascript variable outside script

查看:54
本文介绍了如何在脚本外部获取Javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在javascript变量中获取下拉选择值。当我更改下拉值时,警报正确显示值,并且我使用文本框中的getElementById和显示所选值的文本框获取该值。但外部脚本我无法获得所选的值。如果我回显它显示的值+ + javavar +'。



I'm trying to get dropdown selected value in javascript variable.When I change dropdown value the alert is displaying the value correctly and I'm getting that value using getElementById in the textbox and the textbox displaying the selected value.But outside script I am unable to get the selected value.If I echo the value it is displaying '"+javavar+"'.

<script>
function selecttext()
{
var javavar=document.getElementById("text").value;

document.getElementById("text1").value="<?php

$phpvar='"+javavar+"';

echo $phpvar;?>";
}
</script>
<?php

echo $phpvar;

?>
<body>
<select name="text" id="text" onchange="return selecttext();">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="text" id="text1" name="text1">
</body>







请提出任何建议。




Please give any Suggestions.

推荐答案

phpvar =' + javavar +' ;

echo
phpvar='"+javavar+"'; echo


phpvar;? > ;
}
< / script >
<? php

echo
phpvar;?>"; } </script> <?php echo


phpvar;

>
< body >
< 选择 名称 = text id = text onchange = return selecttext(); >
< 选项 value = 1 > 1 < / option >
< 选项 value = 2 > 2 < / option >
< 选项 value = 3 > 3 < / option >
< / select >
< 输入 类型 = text id = text1 名称 = < span class =code-keyword> text1 >
< / body >
phpvar; ?> <body> <select name="text" id="text" onchange="return selecttext();"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <input type="text" id="text1" name="text1"> </body>







请提出任何建议。




Please give any Suggestions.


这篇关于如何在脚本外部获取Javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆