codecamp

JSLite - HTML代码/文本/值

如有疑问欢迎到这些地方交流,欢迎加入JSLite.io组织团伙共同开发!

segmentfault社区 | 官方网站 | 官方文档-更详细 | Issues

text

取得所有匹配节点对象的文本内容。

$("#box").text() //⇒ string 返回文本
$("#box").text(function(){
    return "这里干点儿什么?"
}) //⇒ string 返回"#box"中的文本

html

获取或设置节点对象内容。

$("#box").html()
//⇒ string 返回包括HTML的文本

val

获取设置input的 value 。

$("input").val() //⇒ string 
$("input").val("test") //⇒ self 


$("#input").val(function(index,oldvalue){
    console.log(index,oldvalue)
    return "111" + oldvalue
}) //⇒ self 

data

读取或写入dom的 data-* 属性。
data(name) ⇒ value
data(name, value) ⇒ self

$("#test").eq(0).data("name",{"sss":1}) //⇒ self
$("#test").eq(0).data("name",[1,2,3,4]) //⇒ self 
$("#test").eq(0).data("name") //⇒ [1,2,3,4]  或者 {"sss":1} 对象
$("#test").data({"aa":1,"www":334343}) //⇒ 设置节点属性 data-aa="1" | data-www="334343"
$("#test").data() //⇒  {"aa":1,"www":334343}
JSLite - 对象访问
JSLite - 节点属性
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }