绑定 cfselects' onClick 导致问题

发布于 2024-11-05 14:56:15 字数 1130 浏览 1 评论 0原文

我有一个工作正常的 cfselect。我有一个 onclick 事件来刷新与 cfselect 的绑定,因为查询内容不断变化,我希望用户拥有更新的列表。现在我想添加“选择任何总线”作为我无法做到的第一个选项去做。

我尝试在查询结果从我的 cfc 返回之前添加一行。但除了“选择任何总线”之外,我无法选择任何其他值。

我的 cfselect 代码是:

<cfinvoke component="getCalculatorData" method="getAllBus"  argumentcollection="#houseArgs#" returnvariable="qry_busList">
<cfform style="align:centre" id="frm_drpDwnBus" name="frm_drpDwnBus"> 
<cfinput name="hdnrr" value="#rrSbstring#" type="hidden">
<cfselect name="dpDwnBs" bindOnLoad="true" 
  bind="cfc:getCalculatorData.getAllBus(hdnrr.value)" 
  value="busType_id_pk" 
  display="busType_name" >
  onclick="javascript:refresh(hdnrr.value)"
  <option value="0" on>Select a Bus</option>
</cfselect> 
</cfform> 

我的 cfc: 选择总线类型_id_pk ,busType_name 来自 tbl_bustype 其中busType_railroad_letter=

javascript:

function refresh(s)
 {
  ColdFusion.Bind.assignValue('dpDwnBs','value', dataCalcu.getAllBus(s))
 }

一旦我删除 onclick 事件,一切都会正常工作。请帮我一下。

I have a cfselect which is working fine. I have an onclick event to refresh the binding to the cfselect because the query contents keep changing quite frequently and I want the users to have the updated list.Now i want to add "Select any Bus" as the first option which I am not able to do.

I tried adding a row to the query result ahead of it being returned from my cfc. But I am not able to select any other value other than 'Select any Bus'.

My cfselect code is:

<cfinvoke component="getCalculatorData" method="getAllBus"  argumentcollection="#houseArgs#" returnvariable="qry_busList">
<cfform style="align:centre" id="frm_drpDwnBus" name="frm_drpDwnBus"> 
<cfinput name="hdnrr" value="#rrSbstring#" type="hidden">
<cfselect name="dpDwnBs" bindOnLoad="true" 
  bind="cfc:getCalculatorData.getAllBus(hdnrr.value)" 
  value="busType_id_pk" 
  display="busType_name" >
  onclick="javascript:refresh(hdnrr.value)"
  <option value="0" on>Select a Bus</option>
</cfselect> 
</cfform> 

My cfc:

SELECT busType_id_pk
,busType_name FROM tbl_bustype
WHERE busType_railroad_letter=

javascript:

function refresh(s)
 {
  ColdFusion.Bind.assignValue('dpDwnBs','value', dataCalcu.getAllBus(s))
 }

As soon as i remove the onclick event all works fine. Please help me out here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花心好男孩 2024-11-12 14:56:15

最初误读了这个问题,让我们再考虑一下。

选择框上的常设 onclick 绑定事件永远不会起作用。要按照大多数人的方式使用选择框,请单击它两次:一次将其下拉,一次选择您的项目。但是,第一次单击时您会重置该项目。即使该框保持打开状态(我怀疑这可能与浏览器相关,但尚未真正测试过),第二次单击也会重置它,这意味着您将失去选择,因为所选项目被销毁并重新创建为新的 DOM 节点。

我可以想到三种解决方案。

首先,您可以向表单添加刷新按钮,然后刷新选择框中的值。

其次,您可以使用jQuery或类似的方法来绑定事件,然后onclick刷新选项列表,然后删除onclick事件绑定。这意味着用户只能刷新选项一次,但(希望)这应该足够了。如果页面用户界面被多次使用(例如通过 AJAX),您可以在提交时重新绑定 onclick 刷新事件。

最后,将表单项显示为不可编辑的文本字段 (onfocus="blur();" IIRC)。添加按钮或更改焦点事件以启动模式窗口,该窗口通过 AJAX 或类似方式从 CFC 中提取选项并显示它们,以便每当他们选择编辑此项目时,他们都会获得一组新的选择。

所有这些都有不保留以前的选择的缺点,因为绑定刷新会破坏所有选项节点并构建新的选项列表。

Having misread the question originally, let's take another swing.

A standing onclick bind event on a select box will never work. To use a select box the way most people do, you click it twice: once to drop it down, and once to select your item. However, on the first click you reset the item. Even if the box stays open (I suspect this might be browser dependent, but hanven't really tested), the second click will also reset it, meaning that you'll lose your selection, as the selected item is destroyed and recreated as a new DOM node.

I can think of three solutions.

First, you can add a refresh button to the form, and refresh the values in the select box then.

Second, you can use jQuery or similar to bind the event, and then onclick refresh the option list and then remove the onclick event binding. This means that the user can only refresh the options once, but (hopefully) that should be enough. If the page uis used multiple times (via AJAX for example) you can rebind the onclick refresh event on submission.

Finally, display the form item as an uneditable text field (onfocus="blur();" IIRC). Add a button, or change the focus event to launch a modal window that pulls the options from your CFC via AJAX or similar and displays them, so that anytime they choose to edit this item, they get a new set of choices.

All of these have the disadvantage of not preserving previous selections, as the bind refresh destroys all the option odes and builds a new option list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文