我需要处理超链接上的onlick函数,但它不起作用..
HTML代码: -
<a href="#" onclick="updateParent()" id="2" value="2">CLICK HERE</a>
Run Code Online (Sandbox Code Playgroud)
jQuery的: -
$(document).ready(function(){
function updateParent(control) {
alert('Hi')
}
})
Run Code Online (Sandbox Code Playgroud)
updateParent只存在于.ready()函数内部.它需要全球化onclick才能发挥作用.
此外,您不应该使用内联事件.你有jQuery,使用它.
<a href="#" id="2" value="2">CLICK HERE</a>
<script>
$(document).ready(function(){
$('#2').click(function(e){
// preventDefault... it prevents the "default" action of the tag
// In this case, it would try to nagivate to `#`. Which would
// scroll the page to the top.
e.preventDefault();
alert('hi');
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |