gpt4 book ai didi

javascript - #encodeForJavaScript()# 的 ColdFusion JavaScript 等效项

转载 作者:行者123 更新时间:2023-11-28 18:17:29 24 4
gpt4 key购买 nike

我有一些表单字段,我正在通过 ajax 调用更新数据库。数据库已成功更新,但如果将 DoubleQuotes 提交到数据库,我无法正确更新表单。

Some "Quotes" are needed按下 Enter 键时作为子任务提交。

数据库会看到Some "Quotes" are needed .

但是页面会看到Some%20%22Quotes%22%20are%20needed在文本框的焦点上 if encodeURI(data.TASKDESCRIPTION)被使用并且。

如果刷新页面页面显示Some "Quotes" are needed成功。

<cfif isDefined("action") and action is "editSubtask">
<cfquery name="udpateSubTask" datasource="#siteDataSource#">
UPDATE ProjectTaskSubtasks
SET taskDescription = <cfqueryparam value="#form.TASKDESCRIPTION#" cfsqltype="cf_sql_varchar" >
WHERE guid = <cfqueryparam value="#form.SUBTASKGUID#" cfsqltype="cf_sql_varchar" >
</cfquery>
<cfquery name="selectSubTask" datasource="#siteDataSource#">
SELECT guid as SUBTASKGUID, taskDescription
FROM ProjectTaskSubtasks
WHERE guid = <cfqueryparam value="#form.SUBTASKGUID#" cfsqltype="cf_sql_varchar" >
LIMIT 1
</cfquery>
<cfoutput>#serializeJSON(selectSubTask, "struct")#</cfoutput>
<cfabort>
</cfif>
<!--- ----------------------------------------- --->
<cfloop query="#subtasks#">
<div id="_#subtasks.guid#" class="col-xs-12">
<input type="text" id="description-#subtasks.guid#" name="description-#subtasks.guid#" class="#subtasks.isComplete is 0 ? '' : 'strike'# subtask-hide col-xs-10" value="#EncodeForHTMLAttribute(subtasks.taskDescription)#" onClick="allowInput(this)"/>
<!--- #EncodeForHTMLAttribute(subtasks.taskDescription)# Works Great for the starting Value of this TextBox from DB especially if doublequotes in subtasks.taskDescription DB Field --->
</div>
<!--- ----------------------------------------- --->
<script>
var taskDescription_#subtasks.guid# = "#encodeForJavaScript(subtasks.taskDescription)#"; //this appears to work as needed

$('##description-#subtasks.guid#').keyup(function(e){
var code = e.which;
if(code===13){
$.post(
'#cgi.SCRIPT_NAME#',
{
action: 'editSubtask',
SUBTASKGUID: $(this).parent()[0].id.replace('_',''),
TASKDESCRIPTION: $(this).val()
},
function(data){
data = JSON.parse(data);
data = data[0];

taskDescription_#subtasks.guid# = encodeURI(data.TASKDESCRIPTION); //THIS DOES NOT WORK if doublequotes where submitted to the DB : when data comes back from editSubTask I need a way to update my Variable so on focus out it updates the field with the new information submitted .
$('##formButt').focus();
}
);
}
});

$('##description-#subtasks.guid#').focusout(function(){
/* .val(taskDescription_#subtasks.guid#)works great HERE on FocusOut doesn't change the Value from original var taskDescription_#subtasks.guid# = "#encodeForJavaScript(subtasks.taskDescription)#" */

$('##description-#subtasks.guid#').val(taskDescription_#subtasks.guid#).removeClass('subtask').addClass('subtask-hide');
setTimeout(function(){
$('##delete-#subtasks.guid#').removeClass('subtask-cancel').addClass('subtask-cancel-hide');
},150)
});
</script>
</cfloop>

最佳答案

为什么要首先将值编码到 taskDescription_#subtasks.guid# 中?

替换此行

taskDescription_#subtasks.guid# = encodeURI(data.TASKDESCRIPTION);

taskDescription_#subtasks.guid# = data.TASKDESCRIPTION;

现在这一行

$('##description-#subtasks.guid#').val(taskDescription_#subtasks.guid#).removeClass('subtask').addClass('subtask-hide');

将正确设置新值。 jQuery 的 .val() 会自动完成所有需要完成的事情。

关于javascript - #encodeForJavaScript()# 的 ColdFusion JavaScript 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40558413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com