【发布时间】:2024-05-17 19:05:02
【问题描述】:
我有这个。
<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 的名称。示例:如果我遍历 state 是 CA 的位置,然后单击 LA,我希望它将“X”分配给 LA。 'X' 应该是所有人的变量。应该能够列出列表,然后单击 LA、Sacramento、Santa Cruise,并将变量设置为与输出相同。我该怎么做呢???我试图将它设置为一个按钮,并将按钮命名为#getcities.city# 并将其命名为#x#,但除非它是一个表单,否则它不会起作用。我不想提交任何东西。只需在循环内准确点击即可动态获取价值。那么至少现在可以说<cfoutput>Here is the city you just clicked: #x#</cfoutput>
【问题讨论】:
-
查找
<a href>以创建链接。还要查<cfqueryparam>的目的 -
取决于你最终想要什么,AJAX 和 jQuery 可能是一种方法。但请务必遵循
cfqueryparam的作用以及为什么不希望未经处理的变量进入数据库的建议。 -
另外,如果您打算使用 ColdFusion,learncfinaweek.com 已过时,但仍然是一个很好的资源。
标签: html loops variables coldfusion cfml