使用JavaScript更改cfform值以进行动态绑定输出 [英] Changing cfform values with javascript for dynamic bind output

查看:261
本文介绍了使用JavaScript更改cfform值以进行动态绑定输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CFM

<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
    function toggleV(value){
        document.getElementById('blah').value = value;
    }
</script>
</head>
<body>
<cfform name="coolfrm">
    <cfinput type="hidden" name="blah" id="blah" value="default">
    <a onclick="toggleV('anothervalue')" style="cursor:pointer;">click Me</a>
</cfform>

<cfdiv bind="cfc:TestCFC.func({coolfrm:blah})"></cfdiv>

</body>
</html>

CFC

<cfcomponent>
    <cfscript>
        remote function func(simpleString){
            return simpleString;
        }
    </cfscript>
</cfcomponent>

我希望这段代码要做的是将cfdiv中的文本从 default更改为 anothervalue 。

What I expect this code to do is change the text in the cfdiv from "default" to "anothervalue".

这与我认为的方式不符,我想知道为什么。

This doesn't work the way I think it should, and I would like to know why.

推荐答案

通过以下方式定义: http://www.w3.org/TR/html4/interact/scripts.html


当控件失去输入焦点并且自获得焦点以来其
的值已被修改时,就会发生onchange事件。

The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.

以编程方式修改字段时,更改事件未正确触发。

The change event isn't firing correctly when you modify the field programmatically.

通过稍微更改JavaScript函数来解决此问题:

Solve this by changing the JavaScript function slightly:

function toggleV(value){
    document.getElementById('blah').value = value;
    ColdFusion.Event.callBindHandlers('blah',null,'change');
}

这篇关于使用JavaScript更改cfform值以进行动态绑定输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆