简体   繁体   English

将PHP变量传递给JavaScript超链接函数

[英]Passing PHP variable to a JavaScript hyperlink function

I'm trying to pass a variable from a PHP array to a JavaScript function. 我正在尝试将变量从PHP数组传递给JavaScript函数。 In the PHP array I have: 在PHP数组中,我有:

echo '<a href="JavaScript:void(0);" onclick="manager(&#39;';echo $Company;echo'&#39;)">'.$Manager.'</td>

If I use the function, 如果我使用该功能,

<script type="text/jscript">
function manager(Value){
alert(Value);
}
</script>

The hyperlink gives me a message box with the correct company for each row, so the PHP part seems OK. 该超链接为我提供了一个消息框,其中每行都有正确的公司,因此PHP部分似乎正常。 Now I want to pass the Company to a page and return the result to a div. 现在,我想将公司传递给页面,然后将结果返回给div。 I've tried using, 我尝试使用

<script type="text/jscript">
function manager() {
$.post('manager.php', { Company: var.Value},
function (output) {
$('#info2').html(output).show();
});
}
</script>

with some variations like “Company: this.Value” and “Company: (Value)” and another method like, 加上“ Company:this.Value”和“ Company:(Value)”之类的变体,以及另一种方法,

<script type="text/jscript">
function manager(Value){
$("#info2").load("manager.php?"+this.manager.Value);
}
</script>

If I put the company in manually like “$("#info2").load("manager.php?Company=ACME”);” it works so I know the manager.php page is OK. I'm pretty sure I just don't know how to pass the variable though the function correctly. Any ideas? Thanks. 如果我像“ $(“#info2”)。load(“ manager.php?Company = ACME”);这样手动放置公司,那么它可以正常工作,所以我知道manager.php页面是可以的。我很确定只是不知道如何正确地通过函数传递变量,有什么想法吗?

<script type="text/jscript">
function manager(Value){
    $("#info2").load("manager.php?"+Value).show();
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM