我有以下 html 代码,我想更改按钮 onclick 的颜色。我使用$("#submitButton").css("background-color","yellow");
但它不会在点击时改变。
这是我的html代码
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.1.0.css" />
<link rel="stylesheet" href="docs/assets/css/jqm-docs.css" />
<link rel="stylesheet" href="docsdemos-style-override.css" />
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" src="jquery.mobile/jquery-1.7.2.min"></script>
<script type="text/javascript" charset="utf-8" src="js/main.js"></script>
<script type="text/javascript">
$( document ).bind( "mobileinit", function()
{
console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
$.mobile.pushStateEnabled = false;
$.mobile.defaultTransition = 'slideup';
});
</script>
<script type="text/javascript" src="jquery.mobile/jquery.mobile-1.1.0.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Form Page</h1>
</div><!-- /header -->
<div data-role="content">
<form id="loginForm">
<!-- Wrap Inputs in fieldcontain which will sort out borders and padding, can cause layout to break -->
<div data-role="fieldcontain">
<label for="firstName"> Username: </label>
<input type="text" name="username" value="" id="username" /> <!-- Use id and name values -->
</div>
<div data-role="fieldcontain">
<label for="password"> Password: </label>
<input type="password" name="password" value="" id="password" /> <!-- Use id and name values -->
</div>
<div data-role="fieldcontain">
<label for="dob"> Date of birth: </label>
<input type="password" name="dob" value="" id="dob" /> <!-- Use id and name values -->
</div>
<div data-role="button">
<input type="submit" data-role="button" value="Login" id="submitButton">
</div>
</form>
</div>
<div data-role="footer">
<h4>Footer content</h4>
</div><!-- /footer -->
</div>
<script type="text/javascript">
$(function()
{
$('#submitButton').on('click', function(e)
{
e.preventDefault();
$(this).css("background-color","yellow");
handleLogin();
});
});
</script>
</body>
</html>
单击提交按钮时,它会调用 handleLogin() 函数,但颜色不会改变。任何帮助将不胜感激。