• jQuery对html元素取值与赋值(转)


    摘要: Jquery给基本控件的取值、赋值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本区域: $("#text_id").attr("value",'');//清空内容 $("#text_id").attr("value",'test');// 填充内容

    Jquery给基本控件的取值、赋值

    TEXTBOX: 
    var str = $('#txt').val();

     $('#txt').val("Set Lbl Value"); 

    1. //文本框,文本区域:
    2. $("#text_id").attr("value",'');//清空内容
    3. $("#text_id").attr("value",'test');// 填充内容

    LABLE:   

    var str = $('#lbl').text();

    $('#lbl').text("Set Lbl Value");

    1.    var valradio = $("input[@type=radio][@checked]").val();
    2.    var item = $('input[@name=items][@checked]').val();
    3. var checkboxval = $("#checkbox_id").attr("value");
    4.    var selectval = $('#select_id').val();
    1. //多选框checkbox:
    2. $("#chk_id").attr("checked",'');//使其未勾选
    3. $("#chk_id").attr("checked",true);// 勾选
    4. if($("#chk_id").attr('checked')==true) //判断是否已经选中
    1. 单选组radio:
    2.  
    3. $("input[@type=radio]").attr("checked",'2'); //设置value=2的项目为当前选中项
    4.  
    5. //下拉框select:
    6. $("#select_id").attr("value",'test');// 设置value=test的项目为当前选中项
    7. $("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
    8. $("#select_id").empty();//清空下拉框
    9.  
    10. 获取一组名为 (items)的radio被选中项的值
    11. var item = $('input[@name=items][@checked]').val();//若未被选中 则val() = undefined
    12. 获 取select被选中项的文本
    13. var item = $("select[@name=items] option[@selected]").text();
    14. select下拉框的第二个元素为当前选中值
    15. $('#select_id')[0].selectedIndex = 1;
    16. radio单选组的第二个元素为当前选中值
    17. $('input[@name=items]').get(1).checked = true;
    18.  
    19. //重置表单
    20. $("form").each(function(){
    21.    .reset();
    22. });
    摘要: Jquery给基本控件的取值、赋值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本区域: $("#text_id").attr("value",'');//清空内容 $("#text_id").attr("value",'test');// 填充内容

    Jquery给基本控件的取值、赋值

    TEXTBOX: 
    var str = $('#txt').val();

     $('#txt').val("Set Lbl Value"); 

    1. //文本框,文本区域:
    2. $("#text_id").attr("value",'');//清空内容
    3. $("#text_id").attr("value",'test');// 填充内容

    LABLE:   

    var str = $('#lbl').text();

    $('#lbl').text("Set Lbl Value");

    1.    var valradio = $("input[@type=radio][@checked]").val();
    2.    var item = $('input[@name=items][@checked]').val();
    3. var checkboxval = $("#checkbox_id").attr("value");
    4.    var selectval = $('#select_id').val();
    1. //多选框checkbox:
    2. $("#chk_id").attr("checked",'');//使其未勾选
    3. $("#chk_id").attr("checked",true);// 勾选
    4. if($("#chk_id").attr('checked')==true) //判断是否已经选中
    1. 单选组radio:
    2.  
    3. $("input[@type=radio]").attr("checked",'2'); //设置value=2的项目为当前选中项
    4.  
    5. //下拉框select:
    6. $("#select_id").attr("value",'test');// 设置value=test的项目为当前选中项
    7. $("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
    8. $("#select_id").empty();//清空下拉框
    9.  
    10. 获取一组名为 (items)的radio被选中项的值
    11. var item = $('input[@name=items][@checked]').val();//若未被选中 则val() = undefined
    12. 获 取select被选中项的文本
    13. var item = $("select[@name=items] option[@selected]").text();
    14. select下拉框的第二个元素为当前选中值
    15. $('#select_id')[0].selectedIndex = 1;
    16. radio单选组的第二个元素为当前选中值
    17. $('input[@name=items]').get(1).checked = true;
    18.  
    19. //重置表单
    20. $("form").each(function(){
    21.    .reset();
    22. });
  • 相关阅读:
    重新整理 .net core 实践篇————配置系统之盟约[五]
    重新整理 .net core 实践篇————依赖注入应用之援军[四]
    重新整理 .net core 实践篇————依赖注入应用之生命法则[三]
    重新整理 .net core 实践篇————依赖注入应用[二]
    重新整理 .net core 实践篇————配置应用[一]
    spring cloud 学习笔记 客户端(本地)均衡负载(三)
    Leetcode之插入区间
    Leetcode之两棵二叉搜索树中的所有元素
    Leetcode之二叉树的层序遍历
    LeetCode之验证二叉搜索树
  • 原文地址:https://www.cnblogs.com/shanlin/p/2051368.html
Copyright © 2020-2023  润新知