導航:首頁 > 編程語言 > js動態更改圖片路徑

js動態更改圖片路徑

發布時間:2025-05-15 10:30:56

㈠ 只用js如何實現表格內容的動態修改

<body>

<tableid='test'>//定義一個table

<tr>

<td></td><td></td>

</tr>

</table>

<script>

vartb=document.getElementById('test');//獲取表格的dom節點

vartd=tb.rows[0].cells[0];//獲取0行0列的td單元格

td.innerHTML='222';//動態修改表格的內容為222

</script>

</body>

思路:

1、獲取表格的dom節點

2、通過rows和cells定位td單元格

3、通過修改innerHTML

(1)js動態更改圖片路徑擴展閱讀:

JS實現動態表格的新增,修改,刪除操作

一、相關JS函數

function setParamslist() {

var tab = document.getElementById("tab");

//表格行數

var rows = tab.rows.length ;

//表格列數

var cells = tab.rows.item(0).cells.length ;

//alert("行數"+rows+"列數"+cells);

var rowData = "";

for(var i=1;i<rows;i++) {

var cellsData = new Array();

for(var j=0;j<cells-1;j++) {

cellsData.push(tab.rows[i].cells[j].innerText);

}

rowData = rowData + "|" + cellsData;

}

document.getElementById("paramslist").value = rowData;

}

//打開相關新增應用參數界面

function openAppParamsPage() {

var param = new Object();

//這個參數一定要傳。

param.win = window;

param.id = 100;

param.name = "test";

param.birthday = new Date();

var result = window.showModalDialog("addParamsItem","dialogWidth:500px;dialogHeight:600px;dialogLeft:200px;dialogTop=200px");

//var temp = document.getElementById("paramslist").value;

//document.getElementById("paramslist").value = temp + result;

addSort(result);

}

// 增加應用參數函數

function addSort(data) {

var name = data;

if(name == ""||name==undefined ) {

return;

}

console.log(data);

var params = data.split(",");

var paramName = params[0];

var paramCode = params[1];

var paramValue = params[2];

var row = document.createElement("tr");

row.setAttribute("id", paramCode);

var cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramName));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramCode));

row.appendChild(cell);

cell = document.createElement("td");

cell.appendChild(document.createTextNode(paramValue));

row.appendChild(cell);

var deleteButton = document.createElement("input");

deleteButton.setAttribute("type", "button");

deleteButton.setAttribute("value", "刪除");

deleteButton.onclick = function () { deleteSort(paramCode); };

cell = document.createElement("td");

cell.appendChild(deleteButton);

row.appendChild(cell);

document.getElementById("sortList").appendChild(row);

}

// 刪除應用參數函數

function deleteSort(id) {

if (id!=null){

var rowToDelete = document.getElementById(id);

var sortList = document.getElementById("sortList");

sortList.removeChild(rowToDelete);

}

}

二、彈出框頁面,新增或者修改參數,並回寫相關數據。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>新增應用</title>

<#include "/views/head.html"/>

</head>

<body>

<div class="body-box">

<div class="clear"></div>

<form >

<table width="100%" cellspacing="1" cellpadding="2" border="0" class="pn-ftable">

<tr>

<td>參數名稱:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramName" name="paramName"/></td>

</tr>

<tr>

<td>參數編碼:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramCode" name="paramCode" required="true" /></td>

</tr>

<tr>

<td>參數值:</td>

<td class="pn-fcontent"><input type="text" maxlength="20" class="" required="true" id="paramValue" name="paramValue" required="true" /></td>

</tr>

<tr>

<td align="center" colspan="4">

<input type="submit" value="保存" onclick="returnResult();"/>

<input type="button" value="返回" onclick="closeWindow();"/>

</td>

</tr>

</table>

</form>

</div>

</body>

</html>

<script type="text/javascript">

//直接關閉窗口

function closeWindow() {

window.close();

}

//獲取值,組裝後返回

function returnResult() {

if(!$('form').valid())

return;

var paramName = document.getElementById("paramName");

var paramCode = document.getElementById("paramCode");

var paramValue = document.getElementById("paramValue");

//alert("value is " + paramName.value + "," + paramCode.value + "," + paramValue.value);

var result = paramName.value + "," + paramCode.value + "," + paramValue.value;

window.returnValue = result;

window.close();

}

</script>

㈡ js動態改變tab背景圖片。求大神賜教,jquery做出來也行。

樣式部分:
.selected {background-image: url('...')}
頁面部分:

<ul id="tab">
<li class="selected">1</li>
<li>2</li>
<li>3</li>
</ul>
js部分:
jQuery('#tab li').click(function(){
jQuery('#tab li').removeClass('selected');
jQuery(this).addClass('selected');

});

閱讀全文

與js動態更改圖片路徑相關的資料

熱點內容
企業網站建設有哪些基礎 瀏覽:682
讀取數據要哪個文件夾 瀏覽:461
微信怎樣接收電腦文件夾 瀏覽:574
蘋果鎖屏後時間沒有了 瀏覽:105
ios描述文件路徑 瀏覽:914
安卓手機音量dong聲 瀏覽:3
南昌哪裡有孩子學編程的 瀏覽:422
無法打開要寫入的文件 瀏覽:282
城信app有什麼用 瀏覽:645
fanuc程序傳輸軟體 瀏覽:211
s博士點評是什麼app 瀏覽:290
app怎麼封裝防紅 瀏覽:577
南通辦公文件櫃有哪些 瀏覽:894
蘋果分享錄音文件到微信 瀏覽:548
win10逐個選擇文件 瀏覽:312
少兒編程適合什麼樣的學生 瀏覽:655
微信怎麼製作語音文件 瀏覽:274
哪些病毒造成文件夾刪不掉 瀏覽:583
vr全景視頻文件怎麼打開 瀏覽:121
eclipse幾個版本 瀏覽:316

友情鏈接