简体   繁体   English

通过链接将变量传递给javascript

[英]Passing a variable to javascript via a link

My website has a javascript variable (addselectedsubdivision) that loads a neighborhood name from a box on the left to a box on the right. 我的网站有一个javascript变量(addselectedsubdivision),该变量将邻居名称从左侧的框加载到右侧的框。 I was hoping I could build a link and then us PHP to add the subdivision letter, neighborhood, and city so that when you click on the link it goes right to this page and loads the neighborhood name in the box on the right. 我希望可以先建立一个链接,然后再向我们使用PHP添加细分字母,街区和城市,以便当您单击链接时,它会直接转到此页面并在右侧的框中加载街区名称。 However, I can't get the variable to pass to the new page. 但是,我无法将变量传递到新页面。 Any suggestions? 有什么建议么?

Website: http://www.mlsfinder.com/va_rein/jonmcachran/index.cfm?primarySearchType=sold&searchType=subdivision&so=a&domain=www.jonsellsvb.com&subdivision_string=p 网站: http : //www.mlsfinder.com/va_rein/jonmcachran/index.cfm?primarySearchType= sold& searchType= subdivision& so=a& domain= www.jonsellsvb.com& subdivision_string= p

Example link: 示例链接:

<a href="http://www.mlsfinder.com/va_rein/jonmcachran/index.cfm?primarySearchType=sold&searchType=subdivision&so=a&domain=www.jonsellsvb.com&subdivision_string=$firstletter" onLoad="addselectedsubdivision($neighborhood||$city);" target="_blank">

What is the onLoad attribute meant to do? onLoad属性的作用是什么?

In index.cfm you will need to have coldfusion code that will output a javascript statement based on the query parameters. index.cfm您将需要具有Coldfusion代码,该代码将基于查询参数输出javascript语句。
So when the serverside sees that it has the arguuments $neighborhood and $city then it will output 因此,当服务器端看到它具有参数$neighborhood$city ,它将输出

...
addselectedsubdivision("cityfromquerystring");
...

This code will have to be contained in an window.onload = function() {...} or equivalent block in order to only be executed after the page has loaded. 该代码将必须包含在window.onload = function() {...}或等效块中,以便仅在页面加载后执行。

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

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