-5

私はこのページを持っています

<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
alert("asdf");
var url = "http://localhost/test/test.php";
$("#button").on("click", function() {
    $('body').load( url );
});
});
</script></head>
<body>
<input type="button" id="button" value="click" />
</body>
</html>

URL のコンテンツを読み込んで本文に入れたいのですが、何も起こらないのはなぜですか? の解き方 ?

4

1 に答える 1

1

I don't see you including jQuery anywhere in that document, which you need to do in order to use the object's properties and methods.

To include your jquery script in your document, you simply add it as a script line to your head tag:

<script type="text/javascript" src="yourscriptpathgoeshere.js"></script>

Take note that it must go before any of the scripts that use jquery.. it cannot go after the script, for instance.

The below code, as an example, works fine for me:

<html>
    <head>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            var url = "http://localhost/testing/test.php";
            $("#button").on("click", function() {
                $('body').load( url );
            });
        });
        </script>
    </head>
    <body>
        <input type="button" id="button" value="click" />
    </body>
</html>

To get the href of a specific link.. provided the html is valid(and only one item has the id 'link'), use the following method: .attr(), in the following manner:

var href = $("#link").attr('href');
于 2013-03-29T19:58:14.203 に答える