javascript - JavaScript 函数中的函数
问题描述
我在按钮上有提交功能。单击“提交”后会弹出一个对话框并要求确认,单击“确定”后会提交表单。
现在我想添加另一个功能,点击“确定”后,表单应该被提交并且页面的背景颜色也应该改变。我写的代码如下。但现在连表格都没有提交。需要帮助!
function myfunction(e)
{
if(!confirm('Are you sure to proceed with this role?')) {
function changecolor(){
backgroundcolor: #0065bd;
}
changecolor();
e.preventDefault();
}
else {
return false;
}
}
解决方案
changecolor
您可以在全局上添加该功能。无需在另一个函数中添加。并通过参数将数据从第一个函数传递到第二个函数
更新
通过更改颜色值classList.add
function myfunction(e) {
if (!confirm('Are you sure to proceed with this role?')) {
changecolor(e); //pass anything
e.preventDefault();
} else {
return false;
}
}
function changecolor(e) { //receive
e.target.classList.add('custom_back')
}
css: 更新了你的代码style.css
.custom_back{
backgroundcolor: #0065bd !important;
}
推荐阅读
- python - 使用 Pandas Dataframe 写入 Excel
- kubernetes - Microk8s pod 卡在 Ubuntu 上待处理
- powershell - 有没有办法使 PowerShell GUI 选项卡透明?
- google-apps-script - 如何修改将公式仅应用于指定数量的行而不是将其应用于整个列的 Google 脚本
- java - 以 html 格式分享文本意图
- javascript - 在具有授权的路由内使用 Socket.io
- javascript - nodejs中的数组数据结构
- snowflake-schema - SnowSql 无响应
- sql - 自联接获取比较同一表中数据的记录
- tcl - 使 Tcl/Expect 语句不那么“贪婪”