【汇智学堂】js/jQuery使用事件之六
原创
©著作权归作者所有:来自51CTO博客作者wx622c0209dfb71的原创作品,请联系作者获取转载授权,否则将追究法律责任
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用jQuery手工触发事件</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<!--<script type="text/javascript" src="js/js6.js"></script>-->
<link rel="stylesheet" type="text/css" href="css/css6.css">
</head>
<script>
function inputHandler(e) {
var chr=String.fromCharCode(e.charCode);
$("p").append(chr);
}
function spanHandler(e) {
var chrCode=e.target.innerHTML.charCodeAt(0);
$("input").trigger({'type':'keypress','charCode':chrCode});
}
$(document).ready(function () {
$("input").keypress(function (e){inputHandler(e)});
$("span").click(function (e){spanHandler(e)});
});
</script>
<body>
<p>Price:</p>
<input type="text" />
<span>$</span>
<span>£</span>
<span>¥</span>
<span>€</span>
</body>
</html>
span{
border-radius: 5px;
margin:3px;
padding:5px;
background-color: #c0c0c0;
border:3px ridge;
display: inline-block;
cursor: pointer;
}
p{
border:4px outset blue;
padding:3px;
color: white;
background-color: blue;
font-size: 30px;
font-weight: bold;
}