javascript代码实例教程-使用jQuery获得内容以及内容的属性

发布时间:2019-01-10 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-使用jQuery获得内容以及内容的属性脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

使用jQuery获得内容以及内容的属性。

代码如下:


<!DOCTYPE htML>
<html>
&nbsp;   <head>
        <;meta charset="utf-8">
        <tITle></title>
        <script src="js/jquery.js"></script>
    </head>
<style>
body{font-family: "微软雅黑";width: 980px; margin: 0 auto; text-align: center;}
    .box{
        width: 300px;
        height: 300px;
        background: green;
        border: 1px solid #e6e6e6;
        line-height: 200px;
        position: absolute;
    }
button{
    border: none;
    background: green;   
    width: 125px;
    height: 50px;
    line-height: 50px;
    color: #fff;
    font-Size: 16px;
    margin-top: 50px;
    font-family: "微软雅黑";
    }
</style>
    <body>
        <button id="BTn1">显示text</button>
        <button id="btn2">显示html</button>
        <button id="btn3">显示输入内容</button>
        <p id="text">这是要显示<b>粗体</b>的节奏</p>
        <br />
        <input id="input" value="买房子">
        <script>
            $(document).ready(function(){
                $("#btn1").click(function(){
                    alert("Text: " + $("#text").text());
                });
                $("#btn2").click(function(){
                    alert("HTML: " + $("#text").html());
                });
                $("#btn3").click(function(){
                    alert("Value: " +$("#input").val());
                });
            });
        </script>
    </body>
</html>

 

Tips:

1、点击事件节点的选择 #botton

2、alert 的代码规则  ("Value: " + $("#id").html)

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-使用jQuery获得内容以及内容的属性全部内容,希望文章能够帮你解决javascript代码实例教程-使用jQuery获得内容以及内容的属性所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。