Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何调用jQuery函数onclick?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何调用jQuery函数onclick?

Javascript 如何调用jQuery函数onclick?,javascript,jquery,html,Javascript,Jquery,Html,当我单击submit按钮时,我正在使用此代码获取to div中页面的当前url。我不知道如何调用onclick函数。如何做到这一点 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>localhost</title> <script type="text/javascript" src="http://code.jquery.com/jq

当我单击submit按钮时,我正在使用此代码获取to div中页面的当前url。我不知道如何调用onclick函数。如何做到这一点

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>localhost</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
        <script type="text/javascript">
            $(function () {
                var url = $(location).attr('href');
                $('#spn_url').html('<strong>' + url + '</strong>');
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="spn_url"></div>
            <input type="submit" value="submit" name="submit">
        </form>
    </body>
</html>

本地服务器
$(函数(){
var url=$(位置).attr('href');
$('spn_url').html('strong>'+url+'');
});
试试这个

HTML

jQuery
$(文档).ready(函数(){
$(“#提交”)。单击(函数(){
var url=$(位置).attr('href');
$('spn_url').html('strong>'+url+'');
});
});
试试这个:

$('form').submit(function(){
    // this function will be raised when submit button is clicked.
    // perform submit operations here
});
请看一看

$(“#提交”)。单击(函数(){
var url=$(位置).attr('href');
$('spn_url').html('strong>'+url+'');
});
试试这个:

HTML:


jQuery:


函数myfunction()
{
var url=$(位置).attr('href');
$('spn_url').html('strong>'+url+'');
}
JS

$(函数(){
var url=$(位置).attr('href');
$('spn_url').html('strong>'+url+'');
$(“#提交”)。单击(函数(){
警报(“点击按钮”);
});
});
html


Tadaaa!RTFM对你来说是一个很好的建议。我更喜欢
。在('click',function(){…})
上,但可能我太挑剔了+1
$(location.attr('href')
可以是
位置。href
,无需传递到jQuery:)
$(document).ready(function () {
    $('#submit').click(function () {
        var url = $(location).attr('href');
        $('#spn_url').html('<strong>' + url + '</strong>');
    });
});
$('form').submit(function(){
    // this function will be raised when submit button is clicked.
    // perform submit operations here
});
$("#submit").click(function () {
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
});
 $(function () {
    var url = $(location).attr('href');
    $('#spn_url').html('<strong>' + url + '</strong>');
    $("#submit").click(function () {
        alert('button clicked');
    });
});
<input id="submit" type="submit" value="submit" name="submit">