码迷,mamicode.com
首页 > Web开发 > 详细

js、jquery、css属性及出错集合

时间:2019-08-24 13:29:30      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:你好   click   col   冒号   ntb   UNC   tps   test   出现   

*)注意使用jquery设置css的语法

css("propertyname","value");#单个时时逗号
css({"propertyname":"value","propertyname":"value",...});#多个时时大括号,中间是冒号

  

 *)jquery和js的方法是不同的

  比如获取和设置textarea的内容 参考链接:https://blog.csdn.net/glgom/article/details/88142605

<script type="text/javascript">
    function change(){
        /** js设置 */
        var test = document.getElementById("test");
        test.innerHTML = "你好,地球!"; //方法1
        test.value = "你好,中国!"; //方法2
        test.innerText = "绿色地球!"; //方法3
 
        /** jq设置 */ 
        $("#test").html("你好、我好、大家好!");  //方法1
        $("#test").val("幸福的日子");  //方法2
        $("#test").text("html好学");  //方法3
    }
</script>

  我犯得错误 就是竟然以为这两个语言只是获取dom元素的方式有区别:

function virtual_click(){
    // $(‘.jfk-button-img‘).click()
    // $(‘#source‘).click()
    console.log(‘事件已运行‘)
    $(‘#source‘).css(‘background‘,‘#5d885d‘);//这个有用#我起初就是因为这样获取然后调用css方法就能设置样式才以为js和jq除了选择方法有区别而已。而完全没有想到过之前学的Atribute()方法和.style.color=‘‘这种方法,而学这些的时候也没有认识到js和jq是不同的,哎
    var tem=$(‘#source‘)#甚至还想到了这个,以为是直接$(‘‘).value=‘‘会出现对象的属性错误这种可笑的想法
    tem.value=‘ ‘;//这个没有用,不知道为啥,现在知道了,当然没用了阿
    tem.val(‘‘);
}

  

 

js、jquery、css属性及出错集合

标签:你好   click   col   冒号   ntb   UNC   tps   test   出现   

原文地址:https://www.cnblogs.com/Gaoqiking/p/11404039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!