zoukankan      html  css  js  c++  java
  • jq杂项方法/工具方法----trim() html() val() text() attr()

    https://www.cnblogs.com/sandraryan/

    $.trim() 函数用于去除字符串两端的空白字符。在中间的时候不会去掉。

    var str = '        去除字符串左右两端的空格,换行   ,制表符。      ';
    res = $ .trim(str);
    console.log(str);
    console.log(res);

    html(); //设置或获取元素的html内容
    text();  //text内容
    val();   //表单value值
    attr();   //属性值(html提供的默认值和自定义值)
    <div class="wrap">this is a wrapppppp
            <p>para</p>
            <mark>mark text</mark>
            <h2>header 2</h2>
        </div>
    
    
    var wrap = $('.wrap');
        var res = wrap.html();
        console.log(res);
    
        res = wrap.text();
        console.log(res);

    wrap.text('hhhhhhhhhh');
    会覆盖掉页面内容。
      <input class="inp" type="text" value="the value">
    
      var inp = $('.inp');
      var res = inp.val();
      console.log(res);
    显示为:

     

     attr

    var h2 = $('.wrap h2');
        var res = h2.attr('class');
        console.log(res);
        
        h2.attr('class','h2');
        res = h2.attr('class');
        console.log(res);
    
        h2.attr('newattr','hi');
        res = h2.attr('newattr');
        console.log(res);

  • 相关阅读:
    学生信息录入系统
    作业11(增删改查listview)
    作业10(qq增删改查)
    作业9
    作业8
    作业7
    右键打开Windows Terminal
    axure 动态面板中滚动条
    TortoiseSVN服务端的配置与使用
    hfs使用小技巧
  • 原文地址:https://www.cnblogs.com/sandraryan/p/11528448.html
Copyright © 2011-2022 走看看