導航:首頁 > 編程語言 > js獲取到span中的值

js獲取到span中的值

發布時間:2025-03-18 16:56:37

js獲取span的內容

不知道樓主是要獲得span里的什麼東西, 你的span里是一個<a>標簽元素啊

不知道專是不是這個意思屬

var span = $('#like_5920');
alert($(span).find('a').text());

輸出: 喜歡(1)

㈡ js如何獲取input輸入框中輸入的值

可以用value屬性獲取input輸入框中的值。

1、新建html文檔,在body標簽中添加input標簽、button標簽和span標簽,點擊按鈕span標簽中顯示輸入框中的值:

㈢ 怎麼利用js取下面的span值,

方法一:.innerText
var a = document.getElementByClassName("active").innerText;

alert(a);

方法二:.innerHTML
var b = document.getElementByClassName("active").innerHTML;

alert(b);

希望給予採納 謝謝

㈣ 急!怎麼用js提取出span標簽內style里的屬性值

CSS的樣式分為三類:
內嵌樣式:是寫在Tag裡面的,內嵌樣式只對所有的Tag有效。
內部樣式:是寫在HTML的裡面的,內部樣式只對所在的網頁有效。
外部樣式表:如果很多網頁需要用到同樣的樣式(Styles),將樣式(Styles)寫在一個以.css為後綴的CSS文件里,然後在每個需要用到這 些樣式(Styles)的網頁里引用這個CSS文件。

getComputedStyle是一個可以獲取當前元素所有最終使用的CSS屬性值。返回的是一個CSS樣式對象([object CSSStyleDeclaration])
currentStyle是IE瀏覽器的一個屬性,返回的是CSS樣式對象

element指JS獲取的DOM對象
element.style //只能獲取內嵌樣式
element.currentStyle //IE瀏覽器獲取非內嵌樣式
window.getComputedStyle(element,偽類) //非IE瀏覽器獲取非內嵌樣式
document.defaultView.getComputedStyle(element,偽類)//非IE瀏覽器獲取非內嵌樣式
註:Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) 之前,第二個參數「偽類」是必需的(如果不是偽類,設置為null),現在可以省略這個參數。

下面的html中包含兩種css樣式,id為tag的div是內嵌樣式,而id為test的div樣式為內部樣式.

<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="Generator"content="EditPlus®">
<metaname="Author"content="YvetteLau">
<metaname="Keywords"content="關鍵字">
<metaname="Description"content="描述">
<title>Document</title>
<style>
#test{
width:500px;
height:300px;
background-color:#CCC;
float:left;
}
</style>
</head>
<body>
<divid="test"></div>
<divid="tag"style="width:500px;height:300px;background-color:pink;"></div>
</body>
</html>
<scripttype="text/javascript">
window.onload=function(){
vartest=document.getElementById("test");
vartag=document.getElementById("tag");

//CSS樣式對象:CSS2Properties{},CSSStyleDeclaration
console.log(test.style);//火狐返回空對象CSS2Properties{},谷歌返回空對象CSSStyleDeclaration{}
console.log(tag.style);//返回CSS2Properties{width:"500px",height:"300px",background-color:"pink"}
//element.style獲取的是內嵌式的style,如果不是內嵌式,則是一個空對象

console.log(tag.style.backgroundColor);//pink
console.log(tag.style['background-color']);//pink
//獲取類似background-color,border-radius,padding-left類似樣式的兩種寫法啊

console.log(test.currentStyle)//火狐和谷歌為Undefined,IE返回CSS對象
console.log(window.getComputedStyle(test,null))//谷歌返回CSSStyleDeclaration{……},火狐返回CSS2Properties{……}
console.log(window.getComputedStyle(test))
//效果同上,但是在Gecko2.0(Firefox4/Thunderbird3.3/SeaMonkey2.1)之前,第二個參數「偽類」是必需的(如果不是偽類,設置為null)

console.log(test.currentStyle.width);//500px(IE)
console.log(window.getComputedStyle(test).width);//500px;
console.log(window.getComputedStyle(test)['width']);//500px;
//document.defaultView.getComputedStyle(element,null)[attr]/window.getComputedStyle(element,null)[attr]
}
</script>

㈤ js里怎麼獲取span裡面的值

  1. 通過id獲span裡面的值

  2. varx1=document.getElementById("testid").innerText;

    alert("x1="+x1);

閱讀全文

與js獲取到span中的值相關的資料

熱點內容
u盤顯示木馬文件刪除怎麼恢復 瀏覽:860
蘋果相冊怎麼看照片在哪個文件夾 瀏覽:635
tgp新版本雙開怎麼跟隨 瀏覽:684
可編程邏輯控制器有哪些種類 瀏覽:145
注銷公司營業執照去什麼網站 瀏覽:917
adobecs6hosts文件 瀏覽:673
鄰區優化工具 瀏覽:192
gis數據都包括什麼信息 瀏覽:971
C編程哪個培訓好 瀏覽:220
反詐騙app怎麼改個人信息 瀏覽:691
java日期加減分鍾 瀏覽:985
無效kmz文件什麼意思 瀏覽:935
數控離子割怎麼編程 瀏覽:141
windows內存映射磁碟文件 瀏覽:73
javajdk中文幫助 瀏覽:128
rhino如何看數據 瀏覽:231
清障車在哪個app可以看 瀏覽:343
網路響應報錯是什麼意思 瀏覽:841
怎麼查看自己qq密碼 瀏覽:177
哪些app可以租兩個月房子 瀏覽:727

友情鏈接