JS動(dòng)態(tài)添加的div點(diǎn)擊跳轉(zhuǎn)到另一頁面實(shí)現(xiàn)代碼
div調(diào)用函數(shù)跳轉(zhuǎn):
var obj = document.getElementById('id');
obj.onclick=function(){
window.location.href="跳轉(zhuǎn)的地址" rel="external nofollow" ;
}
源文件:
<!DOCTYPE html>
<html>
<head>
<title>首頁推薦頁面</title>
<meta name="author" content="Chunna.zheng"/>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8"/>
<style type="text/css">
div.recommendclass {
width: 100%;
height: 60px;
line-height: 60px;
vertical-align: middle;
font-size: 18px;
text-align: center; /*文字水平居中對(duì)齊*/
background-color: #f5f5f5;
}
.mall_contentChild1Class {
display: inline;
width: 40%;
height: 100px;
background-color: #f5f5f5;
}
.mall_contentChild2Class {
display: inline;
width: 60%;
height: 100px;
float: right;
position: relative;
background-color: #f5f5f5;
}
.mall_contentChild2BottomClass {
display: table-cell;
width: 90%;
vertical-align: bottom;
position: absolute;
left: 5px;
bottom: 5px;
background-color: #f5f5f5;
}
.mall_Child2TextLeftClass {
line-height: 16px;
vertical-align: bottom;
background-color: #f5f5f5;
}
.mall_Child2TextRightClass {
float: right;
color: #f3b041;
font-size: 25px;
line-height: 26px;
vertical-align: bottom;
background-color: #f5f5f5;
}
.news_title {
display: block;
font-size: 18px;
vertical-align: center;
background-color: #f5f5f5;
}
.news_message {
display: block;
font-size: 14px;
vertical-align: center;
background-color: #f5f5f5;
}
.news_time {
display: block;
font-size: 12px;
vertical-align: bottom;
position: absolute;
bottom: 5px;
right: 5px;
background-color: #f5f5f5;
}
</style>
</head>
<body style="margin: 0; padding: 0 ">
<div id="mall_news" class="recommendclass">新聞咨訊</div>
<div id="news_content" style="background-color:#f5f5f5"></div>
<script>
var Shu = 2;
var df = document.createElement("div");
for (var i = 0; i <= Shu; i++) {
var oDiv = document.createElement("div");
var divChild1 = document.createElement("div");
divChild1.className = 'mall_contentChild1Class';
var img = document.createElement("img");
img.style.width = "130px";
img.style.height = "100px";
img.src = 'ic_mall_good_stuff.jpg';
divChild1.appendChild(img);
oDiv.appendChild(divChild1);
var divChild2 = document.createElement("div");
divChild2.className = 'mall_contentChild2Class';
var text1 = document.createElement("span");
text1.className = 'news_title';
text1.innerHTML = "我是標(biāo)題";
divChild2.appendChild(text1);
var bottomDiv = document.createElement("div");
var textLeft = document.createElement("span");
textLeft.className = 'news_message';
textLeft.innerHTML = "我是內(nèi)容";
bottomDiv.appendChild(textLeft);
var textRight = document.createElement("span");
textRight.className = 'news_time';
textRight.innerHTML = "2017.09.23";
bottomDiv.appendChild(textRight);
divChild2.appendChild(bottomDiv);
oDiv.appendChild(divChild2);
//添加點(diǎn)擊事件
oDiv.onclick = function(){
window.location.href="file:///android_asset/news.html" rel="external nofollow" ;
}
df.appendChild(oDiv);
}
document.getElementById("news_content").appendChild(df);
</script>
</body>
</html>
總結(jié)
以上所述是小編給大家介紹的JS動(dòng)態(tài)添加的div點(diǎn)擊跳轉(zhuǎn)到另一頁面實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- js實(shí)現(xiàn)的點(diǎn)擊div區(qū)域外隱藏div區(qū)域
- js點(diǎn)擊頁面其它地方將某個(gè)顯示的DIV隱藏
- js點(diǎn)擊彈出div層實(shí)現(xiàn)可拖曳的彈窗效果
- JavaScript鼠標(biāo)事件,點(diǎn)擊鼠標(biāo)右鍵,彈出div的簡(jiǎn)單實(shí)例
- Javascript點(diǎn)擊其他任意地方隱藏關(guān)閉DIV實(shí)例
- JS實(shí)現(xiàn)點(diǎn)擊按鈕控制Div變寬、增高及調(diào)整背景色的方法
- js實(shí)現(xiàn)點(diǎn)擊按鈕后給Div圖層設(shè)置隨機(jī)背景顏色的方法
- javascript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊頁面 移動(dòng)DIV
- javascript實(shí)現(xiàn)點(diǎn)擊按鈕讓DIV層彈性移動(dòng)的方法
- js實(shí)現(xiàn)點(diǎn)擊生成隨機(jī)div
相關(guān)文章
JavaScript實(shí)現(xiàn)預(yù)覽本地上傳圖片功能完整示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)預(yù)覽本地上傳圖片功能,結(jié)合完整實(shí)例形式分析了javascript圖片預(yù)覽相關(guān)的格式正則驗(yàn)證、瀏覽器判斷、頁面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-03-03
js實(shí)現(xiàn)點(diǎn)擊左右按鈕輪播圖片效果實(shí)例
這篇文章主要介紹了js實(shí)現(xiàn)點(diǎn)擊左右按鈕輪播圖片效果的方法,涉及click事件相應(yīng)、animate方法等使用技巧,需要的朋友可以參考下2015-01-01
刪除javascript所創(chuàng)建子節(jié)點(diǎn)的方法
這篇文章主要介紹了刪除javascript所創(chuàng)建子節(jié)點(diǎn)的方法,涉及javascript針對(duì)頁面節(jié)點(diǎn)元素的操作技巧,需要的朋友可以參考下2015-05-05
js focus不起作用的解決方法(主要是因?yàn)閐om元素是否加載完成)
js focus不起作用的解決方法(主要是因?yàn)閐om元素是否加載完成)2010-11-11
Bootstrap modal 多彈窗之疊加關(guān)閉陰影遮罩問題的解決方法
這里也會(huì)遇到一次性關(guān)閉所有modal引起陰影遮罩的問題,也就是所有modal都關(guān)閉了,但是主頁面仍然被陰影遮罩。下面通過本文給大家分享解決方案,需要的朋友參考下吧2017-02-02
JS可視化學(xué)習(xí)向量計(jì)算點(diǎn)到線段的距離并展示
這篇文章主要為大家介紹了JS可視化學(xué)習(xí)向量計(jì)算點(diǎn)到線段的距離并展示實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
js觸發(fā)asp.net的Button的Onclick事件應(yīng)用
由于asp.net采用的是事件驅(qū)動(dòng)模式,所以默認(rèn)用戶按回車并沒有觸發(fā)按鈕的onclick事件。用戶按回車也不是沒有提交表單,通過httpwath可以看到,實(shí)際上頁面表單是提交到了form下的action頁面,只不過沒有觸發(fā)onclick事件而已,感興趣的朋友可以了解下,或許對(duì)你有所幫助2013-02-02
微信小程序仿知乎實(shí)現(xiàn)評(píng)論留言功能
這篇文章主要為大家詳細(xì)介紹了微信小程序仿知乎實(shí)現(xiàn)評(píng)論留言功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11

