zoukankan      html  css  js  c++  java
  • jq——html,text,val和对象访问

    html代码

    1.html():获取的是对象内的html代码,类似于innerHTML

    2.html(代码):设置html的内容,替换

    $("div").html("hhhhh");

    $("div").html("<p>hhhh</p>");

    ps:html要识别标签

    text:标签中的文本内容

    标签中的文本内容

    1.text():获取元素中的文本内容,与innerText类似

    console.log($("div").text());

    2.text(代码):设置元素的文本内容

    $("div").text("这是新内容");

    ps:如果设置的时候有标签,这些标签都会被当作文本处理

    $("div").text("<b>这是新内容</b>");

    val值

    input里面的value值

    1.val():获取value值

    console.log($("input").val());

    2.val(值):设置value值

    $("input").val("新的点击");

    对象访问

    1.length:个数

    console.log($("div").length);

    2.size():个数

    console.log($("div").size());

    3.each:遍历

    each:每个

    用法:元素.each(function(index,element){})

    index:索引下标

    element:元素

    $("div").each(function(n,obj){

    console.log(n); });

    $("div").each(function(n,obj){

    console.log(obj); });

    ps:obj可以用this代替

    $("input").click(function() {

    $("div").each(function(n,obj){

    //console.log(obj);

    $(this).html("这是第"+n+"个");

    });

    });

    this代表当前

  • 相关阅读:
    读取XML并绑定至RadioButtonList
    获取客户端IP地址
    Repeater控件数据导出Excel
    验证用户必选CheckBox控件
    限制CheckBoxList控件只能单选
    获取客户端电脑名称
    获取Repeter的Item和ItemIndex
    获取DataList控件的主键和索引
    InsusExportToExcel Library
    ASP.NET网页打印
  • 原文地址:https://www.cnblogs.com/ellen-mylife/p/10877671.html
Copyright © 2011-2022 走看看