HTML input parameters, multi-line text textarea descriptions, and methods of getting and setting

Description of all types and properties of input

( This article is implemented using Jquery )

Except for special instructions: getting and setting the values ​​of properties and styles can be used uniformly:

属性如:
    name,value,type,id
获取:
    $("#text").attr('属性名')
设置:
    $("#text").attr({属性:"值",属性:"值"})

Get and set properties in css:

属性如:
    color,background,font等
获取
    $("#text").css("color")
设置:
    $("#text").css({属性:"值",属性:"值"})


The first text type or password type

<input type="text" id="text" value="文本框默认显示" name="user">
$("#text").val() //获取文本框的输入

// 设置默认显示
$("#text").attr({value:"默认显示值"})

The second check box

//返回true这该选项被选中,否则未被选中
$("#checkbox").prop('checked')  

// 设置id为checkbox的选择默认是选中的
$("#checkbox").prop({checked:true})

The third radio option (note that the val()obtained value is different from others)

单选input的name属性应该设置为相同的值

$("#radio1").val()  // 获取的是value里面的值

//返回true这该选项被选中,否则未被选中
$("#radio1").prop('checked')

// 设置id为radio1的单选框默认是选中的
$("#radio1").prop({checked:true})

multiline text

$("#many").val() // 获取文本框里面的值

// 如果想设置默认值,执行写在下面就可以了
<textarea id="many" >这里是默认值</textarea>

The pseudocode used in the above description

    文本<input type="text" id="text" value="默认值" name="user">
    密码<input type="password" id="password" value="">
    按钮<input type="button" id="button" value="按钮">
    多选1<input type="checkbox" class="checkbox" value="一">
    多选2<input type="checkbox" id="checkbox" value="二">
    多行文本<textarea id="many" >wowow</textarea>
    单选1<input type="radio" id="radio1" value="22" name="a">
    单选2<input type="radio" id="radio2" value="11" name="a">

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325725726&siteId=291194637