gpt4 book ai didi

javascript - 尝试放置两个javascript

转载 作者:行者123 更新时间:2023-11-29 12:08:45 33 4
gpt4 key购买 nike

我试图放置两个 onClick 函数,但是当我将它们放在一起时出现错误。第一个功能不起作用,这是我的脚本。正如您所看到的,我尝试调用 insertData 函数,然后使用此函数 window.location.reload() 重新加载页面。脚本下方有一张有错误的照片。

if ($canEdit) {
$s .= ("\n\t\t".'<a href="#">'
. "\n\t\t\t".'<img src="./images/icons/tick.png" alt="' . $AppUI->_('Check')
. '" border="0" width="12" height="12" onClick="javascript:insertData('. $currentTasken .', '.$currentUser.', \''.$currentSummary.'\', '.$currentPercent.', \''.$currentDescription.'\'); window.location.reload();" />' . "\n\t\t</a>");
}
$s .= "\n\t</td>";
?>
<script type="text/javascript">

// Note that you should use `json_encode` to make sure the data is escaped properly.
var currentTasken = <?php echo json_encode($currentTasken=$a['task_id']); ?>;
var currentUser = <?php echo json_encode($currentUser=$AppUI->user_id); ?>;
var currentSummary = <?php echo json_encode($currentSummary=$row[0]); ?>;

function insertData(currentTasken, currentUser, currentSummary, currentPercent, currentDescription)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","modules/tasks/datafile.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

// Here, use the JS variables but, likewise, make sure they are escaped properly with `encodeURIComponent`
xmlhttp.send("currentUser=" + encodeURIComponent(currentUser) + "&currentTasken=" + encodeURIComponent(currentTasken) + "&currentSummary=" + encodeURIComponent(currentSummary) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
}

</script>

这是错误的照片: enter image description here

最佳答案

onClick="javascript:doClickStuff('. $currentTasken .', '.$currentUser.', \''.$currentSummary.'\', '.$currentPercent.', \''.$currentDescription.'\');"

让你的click函数调用这两个函数,然后将其设置为click事件

function doClickStuff(data){
insertData(data);
}
function insertData(currentTasken, currentUser, currentSummary, currentPercent, currentDescription)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","modules/tasks/datafile.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

//callback to reload page
xmlhttp.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
window.location.reload();
}
};
// Here, use the JS variables but, likewise, make sure they are escaped properly with `encodeURIComponent`
xmlhttp.send("currentUser=" + encodeURIComponent(currentUser) + "&currentTasken=" + encodeURIComponent(currentTasken) + "&currentSummary=" + encodeURIComponent(currentSummary) + "&currentPercent=" + encodeURIComponent(currentPercent)+ "&currentDescription=" + encodeURIComponent(currentDescription));
}

关于javascript - 尝试放置两个javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056184/

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