循环查询,在点击时动态分配值 ColdFusion



我有这个。

<cfquery name="getcities" datasource="local">
select city, state, ZIP
from table
where state = '#stateval#'
order by city asc
</cfquery>
<cfoutput>
<table>
<thead>
<tr>
<th>City Names in: #stateval#</th>
</tr>
</thead>
<tbody>
<cfloop query="getcities">
<tr>
<td>#getcities.cityname#</td>
</tr>
</cfloop>
</tbody>
</table>
</cfoutput>

定义stateval,即来自选择。循环浏览表格很好。我希望每个输出都是可点击的,单击时,将变量分配给city的名称。示例:如果我遍历stateCA 的位置,然后单击 LA,我希望它将"X"分配给 LA。"X"应该是所有人的变量。应该能够列出列表,然后单击洛杉矶、萨克拉门托、圣塔克鲁斯,并将变量设置为与输出相同。我该怎么做???我尝试将其设置为一个按钮,并将按钮命名为#getcities.city#并将其命名为#x#但除非它是一个表单,否则这将不起作用。我不想提交任何东西。只需在循环内准确点击即可动态获取值。那么至少现在能够说<cfoutput>Here is the city you just clicked: #x#</cfoutput>

具有onClick操作的简单href将为您执行此操作。下面是警报的示例。

<cfquery name="getcities" datasource="local">
select city, state, ZIP
from table
where state = <cfqueryparam cfsqltype="cf_sql_varchar" value="#stateval#">
order by city asc
</cfquery>
<cfoutput>
<table>
<thead>
<tr>
<th>City Names in: #stateval#</th>
</tr>
</thead>
<tbody>
<cfloop query="getcities">
<tr>
<td><a href="##" onClick="alert('#getcities.cityname#')">#getcities.cityname#</a></td>
</tr>
</cfloop>
</tbody>
</table>
</cfoutput>

另外,查找cfqueryparam以及为什么它很重要。

https://helpx.adobe.com/coldfusion/developing-applications/accessing-and-using-data/accessing-and-retrieving-data/enhancing-security-with-cfqueryparam.html

我将循环结果填充到div中,然后使用jquery读取div的值,并通过URL将其作为变量传递。像魅力一样工作。

最新更新