㈠ 想在一個div裡面添加圖片,用js怎麼寫啊
1、猛檔新建一個HTML文件,保存為test.html,用於編寫代碼實現拖放功能 。
㈡ 怎麼用JS動態更改DIV層的背景色
需要准備的材料分別有:電腦、html編輯器、游賣瀏覽器。
1、首先坦皮,打開html編輯器,新建html文件,例如:index.html,神信逗填寫問題基礎代碼。
㈢ 關於JS腳本中,單擊後重新給DIV設置背景圖片~
你好:
我把樓上的改了下,看看是不是你要的
提示:把代碼保存為a.htm即可預覽效果
<script>
function setDivBG(s)
{
document.getElementById("div1").className=s;
}
</script>
<head>
<style type="text/css">
.style1
{
width: 100px;
height: 100px;
background-image:url('http://img..com/img/logo-.gif');
}
.style2
{
width: 100px;
height: 100px;
background-image:url('http://img..com/img/iknow/images/r1s1g5.gif');
}
</style>
</head>
<BODY >
<select onchange="setDivBG(this.value);">
<option value="style1">知道</option>
<option value="style2">頭像</option>
</select>
<div id="div1" class="style2" >
</div>
</BODY>
㈣ 我想在js頁面獲取jsp頁面的一個div並在js里調用方法給它添加圖片,用什麼方法
有兩種方式
1.獲取到div之後,編輯一個img元素,並指定好url地址。然後div append img 元素就好了。
2.獲取到div之後,用js給div設置背景圖片就可以了。
㈤ js如何用定時器實現逐步給多個div加背景顏色並一直循環給顏色
跑馬燈效果嗎
<html>
<head>
<title>簡單循環變色</title>
<style>
#a>div{
width:100px;
height:100px;
float:left;
}
</style>
</head>
<body>
<divid="a">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<虧答激/div>
<script>
function$(id){
銷襪return(document.getElementById(id));
}
varint=setInterval("clock()",500);
functionclock(){
for(vari=0;i舉基<$('a').children.length-1;i++){
$('a').children[i].style["background-color"]=$('a').children[i+1].style["background-color"];
}
$('a').children[$('a').children.length-1].style["background-color"]='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
}
</script>
</body>
</html>
希望可以幫到你
㈥ js 實現div背景圖片的填充效果
給<img>加個id屬性 然後在js中獲取到這<img>
document.getElementByID("id").src="(路徑)";
㈦ 在「js」中怎麼設置div的背景圖片
有兩種比較直接的方式,x0dx0ax0dx0a第李銀一種方法茄銷:預先設置一個樣式,然後在js中操作,給div加上這個class。x0dx0ahtml代碼:x0dx0a-----x0dx0a
㈧ 用JS設置div的背景圖問題
background是全局的背景設置,例如
body{
background:#fffurl('xxx.png')no-repeat
}
拆分出來就是
body{
background-color:#fff;
background-image:url('xxx.png');
background-repeat:no-repeat;
}
你設置了obj.style.background就覆蓋了background-image,所以你要改成這樣
obj.style.backgroundImage='url("xxx.png")'
㈨ js如何用定時器實現逐步給多個div加背景顏色
用jQuery實現很簡單
1、變高:明咐 $("#divId").height($("#divId").height() + 10);
2、變寬:好高 $("#divId").width($("#divId").width() + 10);
3、變背景色: $("#divId").css('background', '友槐尺red');