问题
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>
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.
回答1:
By definition from: http://www.w3.org/TR/html4/interact/scripts.html
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.
Solve this by changing the JavaScript function slightly:
function toggleV(value){
document.getElementById('blah').value = value;
ColdFusion.Event.callBindHandlers('blah',null,'change');
}
来源:https://stackoverflow.com/questions/7652136/changing-cfform-values-with-javascript-for-dynamic-bind-output